lambda-ice5 fails with a checking ICE when run with -fpermissive because
seen_error returns 0. This calls maybe_diagnose_erroneous_template in
tsubst_lambda_expr, which reports the error and fixes the ICE.

        PR c++/118388

gcc/cp/ChangeLog:

        * pt.cc (tsubst_lambda_expr): Call
        maybe_diagnose_erroneous_template.

gcc/testsuite/ChangeLog:

        * g++.dg/cpp0x/lambda/lambda-ice5-fpermissive.C: New test.

---
Jason had suggested that we might be missing such a call in his review
last year.

 gcc/cp/pt.cc                                      |  7 +++++++
 .../g++.dg/cpp0x/lambda/lambda-ice5-fpermissive.C | 15 +++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice5-fpermissive.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index fd60878ef2a6..b344a120714e 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -21247,6 +21247,13 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t 
complain, tree in_decl)
   tree oldfn = lambda_function (t);
   in_decl = oldfn;
 
+  /* If the lambda is within a template, permissive errors that might have
+     occured when parsing its parameters are linked to the closure's template
+     declaration. Make sure they're reported.  */
+  tree closure = LAMBDA_EXPR_CLOSURE (t);
+  if (TYPE_TEMPLATE_INFO (closure))
+    maybe_diagnose_erroneous_template (TYPE_TI_TEMPLATE (closure));
+
   args = add_extra_args (LAMBDA_EXPR_EXTRA_ARGS (t), args, complain, in_decl);
   if (processing_template_decl
       && (!in_template_context || (complain & tf_partial)
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice5-fpermissive.C 
b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice5-fpermissive.C
new file mode 100644
index 000000000000..08a4bd9992a1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice5-fpermissive.C
@@ -0,0 +1,15 @@
+// PR c++/118388
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-fpermissive" }
+
+template<int> int foo()
+{
+  [] (void i) { return 0; } (0); // { dg-warning "invalid" }
+                                // { dg-error "erroneous" "" { target *-*-* } 
.-1 } */
+  return 0;
+}
+
+void bar()
+{
+  foo<0>();
+}
-- 
2.56.0


Reply via email to