[PR c++/84375] Fix ICE after bad friend
authorNathan Sidwell <nathan@gcc.gnu.org>
Fri, 16 Feb 2018 14:30:55 +0000 (14:30 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Fri, 16 Feb 2018 14:30:55 +0000 (14:30 +0000)
https://gcc.gnu.org/ml/gcc-patches/2018-02/msg00987.html
PR c++/84375
* name-lookup.c (do_pushdecl): Bail out on bad local friend injection.

* g++.dg/lookup/pr84375.C: New.

From-SVN: r257739

gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/lookup/pr84375.C [new file with mode: 0644]

index ecd52d04b97c1bd03c0918fecb6112d029b7ccad..ee3ade9bd050845910d6673ec9927ef2965bcbf9 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-16  Nathan Sidwell  <nathan@acm.org>
+
+       PR c++/84375
+       * name-lookup.c (do_pushdecl): Bail out on bad local friend injection.
+
 2018-02-15  Jason Merrill  <jason@redhat.com>
 
        PR c++/83227 - C++17 ICE with init-list derived-to-base conversion.
index e5a340037020c128befb88bafad1ca8c1dd8facb..47cee30338db2c6aaa77e71cda7907448978a62d 100644 (file)
@@ -3079,12 +3079,16 @@ do_pushdecl (tree decl, bool is_friend)
          if (is_friend)
            {
              if (level->kind != sk_namespace)
-               /* In a local class, a friend function declaration must
-                  find a matching decl in the innermost non-class scope.
-                  [class.friend/11] */
-               error ("friend declaration %qD in local class without "
-                      "prior local declaration", decl);
-             else if (!flag_friend_injection)
+               {
+                 /* In a local class, a friend function declaration must
+                    find a matching decl in the innermost non-class scope.
+                    [class.friend/11] */
+                 error ("friend declaration %qD in local class without "
+                        "prior local declaration", decl);
+                 /* Don't attempt to push it.  */
+                 return error_mark_node;
+               }
+             if (!flag_friend_injection)
                /* Hide it from ordinary lookup.  */
                DECL_ANTICIPATED (decl) = DECL_HIDDEN_FRIEND_P (decl) = true;
            }
index 7cd64bb15ffcae584cc040906a672e4d64a4c604..58eb38582d918ef8e371381ce3c01d03e4a46539 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-16  Nathan Sidwell  <nathan@acm.org>
+
+       PR c++/84375
+       * g++.dg/lookup/pr84375.C: New.
+
 2018-02-14  Oleg Endo  <olegendo@gcc.gnu.org>
 
        PR target/83831
@@ -29,7 +34,7 @@
 2018-02-15  Martin Sebor  <msebor@redhat.com>
 
        * gcc.dg/lto/README (dg-lto-warning, dg-lto-message): Document new
-       directives.     
+       directives.
 
 2018-02-15  Janus Weil  <janus@gcc.gnu.org>
 
diff --git a/gcc/testsuite/g++.dg/lookup/pr84375.C b/gcc/testsuite/g++.dg/lookup/pr84375.C
new file mode 100644 (file)
index 0000000..24cdcb2
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/84375 ICE after error
+
+void foo()
+{
+  struct A
+  {
+    friend void A(); // { dg-error "local class without prior local" }
+  };
+}