struct A { A(int val){} }; int main() { A a{ [x=123]{ return x; }() }; } init-capture2.cpp: In function ‘int main()’: init-capture2.cpp:7:11: error: ‘x’ was not declared in this scope A a{ [x=123]{ return x; }() }; Clang recently fixed this bug, for clang it was caused by the parser getting confused with the lambda and designated initializers, perhaps gcc has a similar bug. With parentheses the code works: struct A { A(int val){} }; int main() { A a( [x=123]{ return x; }() ); }
In our case the issue is slightly different, the problem is in cp_parser_initializer_list, here: cp_parser_parse_tentatively (parser); cp_lexer_consume_token (parser->lexer); designator = cp_parser_constant_expression (parser, true, &non_const); cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE); cp_parser_require (parser, CPP_EQ, RT_EQ); if (!cp_parser_parse_definitely (parser)) designator = NULL_TREE; else if (non_const) require_potential_rvalue_constant_expression (designator); where cp_parser_constant_expression is tentatively called. I think it can be solved by looking forward for the '=', similarly to other GNU extensions, for example compound literals.
Mine.
Author: paolo Date: Tue Sep 23 18:07:59 2014 New Revision: 215528 URL: https://gcc.gnu.org/viewcvs?rev=215528&root=gcc&view=rev Log: /cp 2014-09-23 Paolo Carlini <paolo.carlini@oracle.com> PR c++/61857 * parser.c (cp_parser_skip_to_closing_square_bracket, cp_parser_array_designator_p): New. (cp_parser_initializer_list): Use the latter. /testsuite 2014-09-23 Paolo Carlini <paolo.carlini@oracle.com> PR c++/61857 * g++.dg/cpp1y/lambda-init10.C: New. Added: trunk/gcc/testsuite/g++.dg/cpp1y/lambda-init10.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/parser.c trunk/gcc/testsuite/ChangeLog
Fixed.