PR c++/60190
        * parser.c (cp_parser_lambda_declarator_opt): Pop template parameter
        scope whenever a template parameter list has been started, independent
        of whether the function call operator was well-formed or not.

        PR c++/60190
        * g++.dg/cpp1y/pr60190.C: New testcase.
---
 gcc/cp/parser.c                      | 16 ++++++++--------
 gcc/testsuite/g++.dg/cpp1y/pr60190.C |  5 +++++
 2 files changed, 13 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/pr60190.C

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 57001c6..15a1128 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -9127,15 +9127,15 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, 
tree lambda_expr)
        DECL_ARTIFICIAL (fco) = 1;
        /* Give the object parameter a different name.  */
        DECL_NAME (DECL_ARGUMENTS (fco)) = get_identifier ("__closure");
-       if (template_param_list)
-         {
-           fco = finish_member_template_decl (fco);
-           finish_template_decl (template_param_list);
-           --parser->num_template_parameter_lists;
-         }
-       else if (parser->fully_implicit_function_template_p)
-         fco = finish_fully_implicit_template (parser, fco);
       }
+    if (template_param_list)
+      {
+       fco = finish_member_template_decl (fco);
+       finish_template_decl (template_param_list);
+       --parser->num_template_parameter_lists;
+      }
+    else if (parser->fully_implicit_function_template_p)
+      fco = finish_fully_implicit_template (parser, fco);
 
     finish_member_declaration (fco);
 
diff --git a/gcc/testsuite/g++.dg/cpp1y/pr60190.C 
b/gcc/testsuite/g++.dg/cpp1y/pr60190.C
new file mode 100644
index 0000000..d5e2567
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/pr60190.C
@@ -0,0 +1,5 @@
+// PR c++/60190
+// { dg-do compile }
+// { dg-options "-std=c++1y" }
+
+auto f = []<int>() -> int() {}; // { dg-error "returning a function|expected" }
-- 
1.8.5.5

Reply via email to