Hi!

In this case, because the corresponding variable is errorneous, we end up
with error_mark_node in LAMBDA_TYPE_EXTRA_SCOPE.  This patch just makes sure
we won't crash on it.  Not 100% sure if this is the best fix though.

Bootstrapped/regtested on x86_64-linux and i686-linux.

2018-02-19  Jakub Jelinek  <ja...@redhat.com>

        PR c++/84446
        * pt.c (template_class_depth): Don't crash if LAMBDA_TYPE_EXTRA_SCOPE
        is error_mark_node.

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

--- gcc/cp/pt.c.jj      2018-02-19 10:48:00.328184302 +0100
+++ gcc/cp/pt.c 2018-02-19 13:07:00.680855104 +0100
@@ -389,7 +389,11 @@ template_class_depth (tree type)
       if (DECL_P (type))
        type = CP_DECL_CONTEXT (type);
       else if (LAMBDA_TYPE_P (type))
-       type = LAMBDA_TYPE_EXTRA_SCOPE (type);
+       {
+         type = LAMBDA_TYPE_EXTRA_SCOPE (type);
+         if (type == error_mark_node)
+           break;
+       }
       else
        type = CP_TYPE_CONTEXT (type);
     }
--- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice27.C.jj 2018-02-19 
13:11:15.292869216 +0100
+++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice27.C    2018-02-19 
13:10:45.186870424 +0100
@@ -0,0 +1,12 @@
+// PR c++/84446
+// { dg-do compile { target c++11 } }
+
+template <int>
+void
+foo ()
+{
+  int i;
+  auto i = [] { virtual; }();  // { dg-error "conflicting declaration" }
+                               // { dg-error "templates may not be 'virtual'" 
"" { target *-*-* } .-1 }
+                               // { dg-error "declaration does not declare 
anything" "" { target *-*-* } .-2 }
+}

        Jakub

Reply via email to