Boiling a problem I'm having down to its essence, I can initialize a variable as an int by first executing a do-nothing lambda in a comma expression like this:
int main(){
auto x = ( []{}(), 10 ); // same effect as auto x = 10;
}
But if I don't parenthesize the initializing expression,
int main(){
auto y = []{}(), 10; // won't compile
}
all of gcc, clang, and MSVC complain about trying to initialize y
with a void
expression.
Why do I have to parenthesize the comma expression to use it as an initializer?
x
is initialized actually?static_assert
is executed at compile time anyways. I don't think it's actually necessary to put it inside a lambda expression.auto x = []{ return 10; }();
? Much clearer.