Commit 2b0a6274 by Marek Polacek Committed by Marek Polacek

PR c++/89686 - mixing init-capture and simple-capture in lambda.

	* parser.c (cp_parser_lambda_introducer): Give error when combining
	init-capture and simple-capture.

	* g++.dg/cpp2a/lambda-pack-init2.C: New test.

From-SVN: r269659
parent 84083a71
......@@ -8,6 +8,10 @@
(cp_parser_constructor_declarator_p): Add FLAGS parameter. Pass it to
cp_parser_type_specifier.
PR c++/89686 - mixing init-capture and simple-capture in lambda.
* parser.c (cp_parser_lambda_introducer): Give error when combining
init-capture and simple-capture.
2019-03-11 Jason Merrill <jason@redhat.com>
PR c++/86521 - wrong overload resolution with ref-qualifiers.
......
......@@ -10609,12 +10609,13 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
}
bool init_pack_expansion = false;
location_t ellipsis_loc = UNKNOWN_LOCATION;
if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS))
{
location_t loc = cp_lexer_peek_token (parser->lexer)->location;
ellipsis_loc = cp_lexer_peek_token (parser->lexer)->location;
if (cxx_dialect < cxx2a)
pedwarn (loc, 0, "pack init-capture only available with "
"%<-std=c++2a%> or %<-std=gnu++2a%>");
pedwarn (ellipsis_loc, 0, "pack init-capture only available with "
"%<-std=c++2a%> or %<-std=gnu++2a%>");
cp_lexer_consume_token (parser->lexer);
init_pack_expansion = true;
}
......@@ -10719,8 +10720,21 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS))
{
location_t loc = cp_lexer_peek_token (parser->lexer)->location;
cp_lexer_consume_token (parser->lexer);
capture_init_expr = make_pack_expansion (capture_init_expr);
if (init_pack_expansion)
{
/* If what follows is an initializer, the second '...' is
invalid. But for cases like [...xs...], the first one
is invalid. */
if (cp_lexer_next_token_is (parser->lexer, CPP_EQ)
|| cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN)
|| cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
ellipsis_loc = loc;
error_at (ellipsis_loc, "too many %<...%> in lambda capture");
continue;
}
}
}
2019-03-13 Marek Polacek <polacek@redhat.com>
PR c++/89686 - mixing init-capture and simple-capture in lambda.
* g++.dg/cpp2a/lambda-pack-init2.C: New test.
2019-03-13 Janus Weil <janus@gcc.gnu.org>
PR fortran/89601
......
// PR c++/89686
// { dg-do compile { target c++2a } }
template <typename... Ts>
void foo(Ts... xs)
{
int i = 10;
[...xs...]{}(); // { dg-error "4:too many ..... in lambda capture" }
[...xs...=xs]{}(); // { dg-error "9:too many ..... in lambda capture|expected" }
[xs...]{}();
[...xs=xs]{}();
[i, ...xs...]{}(); // { dg-error "7:too many ..... in lambda capture" }
[i, ...xs...=xs]{}(); // { dg-error "12:too many ..... in lambda capture|expected" }
[i, xs...]{}();
[i, ...xs=xs]{}();
}
int main()
{
foo(0, 1, 2);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment