re PR c++/54947 ([C++11] lambda cannot capture-by-copy inside braced-init-list)

PR c++/54947
	* parser.c (cp_parser_initializer_list): Don't require an
	expression in [] to be constant until we know it's a C99
	designator.

From-SVN: r194256
This commit is contained in:
Jason Merrill 2012-12-06 09:45:11 -05:00 committed by Jason Merrill
parent 695edbac5c
commit 9e04d8a2a0
3 changed files with 36 additions and 1 deletions

View File

@ -1,5 +1,10 @@
2012-12-06 Jason Merrill <jason@redhat.com>
PR c++/54947
* parser.c (cp_parser_initializer_list): Don't require an
expression in [] to be constant until we know it's a C99
designator.
PR c++/55015
PR c++/53821
* semantics.c (maybe_add_lambda_conv_op): Revert earlier change.

View File

@ -17923,11 +17923,14 @@ cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p)
/* In C++11, [ could start a lambda-introducer. */
cp_parser_parse_tentatively (parser);
cp_lexer_consume_token (parser->lexer);
designator = cp_parser_constant_expression (parser, false, NULL);
bool non_const = false;
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);
}
else
designator = NULL_TREE;

View File

@ -0,0 +1,27 @@
// PR c++/54947
// { dg-options -std=gnu++11 }
struct X
{
template<typename L>
X(L)
{ }
};
template<typename A>
void
test()
{
int i = 0;
A a_ok_1( [=] { return i; } ); // OK
A a_ok_2( [i] { return i; } ); // OK
A a_err_1{ [i] { return i; } }; // error
A a_err_2{ [=] { return i; } }; // error
}
int main()
{
test<X>();
}