#include <iostream>
void fun(int a = sizeof(a)){
std::cout<< a<<std::endl;
}
int main(){
fun();
}
Consider this case. Clang accepts it while GCC rejects it. According to [dcl.fct.default] p9
A default argument is evaluated each time the function is called with no argument for the corresponding parameter. A parameter shall not appear as a potentially-evaluated expression in a default argument.
[basic.def.odr] p2
An expression or conversion is potentially evaluated unless it is an unevaluated operand
sizeof
is not a potentially-evaluated expression and a
can be found at this point. I wonder which one is correct for this case?