class A {
public:
int a;
char b;
double c;
A ( int x, char y, double z ) : a(x), b(y), c(z){}
};
int main(){
auto lambda = []( auto x ) {
static auto y = x;
// y = x;
return y;
};
int a = lambda(1);
char b = lambda('a');
double c = lambda(1.5);
A d = lambda( A( 2, 'b', 2.5 ) );
return 0;
}
This code compiles in Clang 3.8.0 and GCC 5.4.0, and works fine. However, taking into account that variable y is static:
- What is the type of variable
y? Does the type ofychange in every call to the lambda? - Is variable
yinitialized in every call in spite of beingstatic? The commented assignment// y = xis not needed to update the value of variabley. - Is this behaviour C++14 Standard compliant?
If I print the sizeof(y) in each call I get 4, 1, 8 and 16 respectively.