如果在C++中定义了一个新变量,那么可以在初始化表达式中使用该变量的名称,例如:
int x = sizeof(x);
那么函数参数的默认值呢?在那里可以使用参数名称引用参数吗?例如:
And what about default value of a function argument? Is it allowed there to reference the argument by its name? For example:
void f(int y = sizeof(y)) {}
这个函数在Clang中被接受,但在GCC中被拒绝,并出现错误:
'y' was not declared in this scope
演示: https://gcc.godbolt.org/z/YsvYnhjTb
哪个编译器是正确的?