C++中的顶级是什么?

Jer*_*rry 5 c++ language-lawyer c++11

示例 14 中[dcl.init.list],标准在描述使用列表初始化的代码语义时,在缩小转换的上下文中使用术语“顶级”。我不知道这是什么意思。

此代码执行没有错误:

int f(int a) { return 1;}

int main() {
    int a[] = {f(2), f(2.0)};  
    int b[] = {f(2.0), f(2)}; // No error because: double-to-int conversion is not at the top-level
}
Run Code Online (Sandbox Code Playgroud)

我也尝试了以下方法。我认为这与初始化顺序无关:

int f(int a) { return 1;}

int main() {
    int a[] = {f(2), f(2.0)};  
    int b[] = {f(2.0), f(2)}; // double-to-int conversion is not at the top-level
    //int c[] = {f(2147483645.0f), f(2)}; // This is erroring out due to narrowing.
    int d[] = {f(2), f(2.0)};  // Now I'm sure top-level doesn't mean the order of initialization. 
}
Run Code Online (Sandbox Code Playgroud)

我想知道什么是顶级?这里这里的文档没有描述它。

我对这个术语感到好奇的原因是因为我试图了解当隐式调用缩小转换时列表初始化程序何时工作。

我也不确定术语。例如,是否有顶级类、顶级类型或顶级列表初始化器之类的东西?

Hol*_*Cat 6

这不是一个严格定义的术语。但是在[dcl.init.list]/note-7您链接的情况下,“在顶层”似乎意味着“直接写在花括号列表中,而不是在嵌套表达式中”。

所以,在int x[] = {1.0, f(2.0)};1.0是在顶层,因为它直接写在桁名单,但2.0并不是因为它是嵌套在一个函数调用表达。