Why can't I access the default argument in my initializer in gcc?

This compiles in clang , but not in gcc :

void f(int x = decltype(x){}); 

A bug in gcc says that x not declared in this scope, but according to 3.3.2 / 1, the variable x should be in scope:

The declaration point for the name immediately after its full declaration (section 8) and before its initializer (if any), except as noted below. [Example:

 int x = 12; { int x = x; } 

Here the second x initialized with its own (undefined) value. - end of example]

So right? Should x be available in its own initializer?

PS: int x = x as a parameter does not work in both compilers, but I do not know why.

+8
c ++ language-lawyer c ++ 11
source share
1 answer

GCC is correct; this is not valid.

C ++ 11 8.3.6 / 9 [dcl.fct.default] function parameters should not be used in the default argument, even if they are not evaluated.

+10
source share

All Articles