Hi, Thanks for the feedback. I chose to take the example from the bug report verbatim as the test case.
However, I agree it makes sense to have the simplest possible test case that reproduces the issue. Here is an updated patch. 2018-02-27 Håkon Sandsmark <hsandsm...@gmail.com> PR c++/71546 - lambda capture fails with "was not declared in this scope" * parser.c (cp_parser_lambda_introducer): Clear scope after each lambda capture. * g++.dg/cpp1y/pr71546.C: New test. 2018-02-27 19:15 GMT+01:00 Paolo Carlini <paolo.carl...@oracle.com>: > .. or even: > > namespace n { struct make_shared { }; } > > int main() > { > int x1; > [e = n::make_shared (), x1]() {}; > } > > I.e., I don't think the fact that std::make_shared is a template plays a > specific role here. > > Paolo.
diff --git gcc/cp/parser.c gcc/cp/parser.c index bcee1214c2f..fc11f9126d3 100644 --- gcc/cp/parser.c +++ gcc/cp/parser.c @@ -10440,6 +10440,12 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr) capture_init_expr, /*by_reference_p=*/capture_kind == BY_REFERENCE, explicit_init_p); + + /* If there is any qualification still in effect, clear it + * now; we will be starting fresh with the next capture. */ + parser->scope = NULL_TREE; + parser->qualifying_scope = NULL_TREE; + parser->object_scope = NULL_TREE; } cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE); diff --git gcc/testsuite/g++.dg/cpp1y/pr71546.C gcc/testsuite/g++.dg/cpp1y/pr71546.C new file mode 100644 index 00000000000..934a6b32364 --- /dev/null +++ gcc/testsuite/g++.dg/cpp1y/pr71546.C @@ -0,0 +1,11 @@ +// PR c++/71546 +// { dg-do compile { target c++14 } } +// { dg-options "" } + +namespace n { struct make_shared { }; } + +int main() +{ + int x1; + [e = n::make_shared (), x1]() {}; +}