re PR c++/84843 (C++ ICE on builtin redefinition since r258391)
authorJakub Jelinek <jakub@redhat.com>
Tue, 13 Mar 2018 20:32:54 +0000 (21:32 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 13 Mar 2018 20:32:54 +0000 (21:32 +0100)
PR c++/84843
* decl.c (duplicate_decls): For redefinition of built-in, use error
and return error_mark_node.  For redeclaration, return error_mark_node
rather than olddecl if !flag_permissive.

* g++.dg/ext/pr84843-1.C: New test.
* g++.dg/ext/pr84843-2.C: New test.

From-SVN: r258503

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/pr84843-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/pr84843-2.C [new file with mode: 0644]

index da81495e8a4ecc61f72ed7707361c67679ae0f96..09dc2b1ac1229d8226361aa482cd2c977f49b7bc 100644 (file)
@@ -1,3 +1,10 @@
+2018-03-13  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/84843
+       * decl.c (duplicate_decls): For redefinition of built-in, use error
+       and return error_mark_node.  For redeclaration, return error_mark_node
+       rather than olddecl if !flag_permissive.
+
 2018-03-13  Jason Merrill  <jason@redhat.com>
 
        PR c++/82565 - ICE with concepts and generic lambda.
index afd04cea630edcbc80b7900414a55f0b160268ef..ff6dd66e7693d579d2222bc7916113065353dd03 100644 (file)
@@ -1583,13 +1583,20 @@ next_arg:;
                          || memcmp (name + len - strlen ("_chk"),
                                     "_chk", strlen ("_chk") + 1) != 0))
                    {
+                     if (DECL_INITIAL (newdecl))
+                       {
+                         error_at (DECL_SOURCE_LOCATION (newdecl),
+                                   "definition of %q#D ambiguates built-in "
+                                   "declaration %q#D", newdecl, olddecl);
+                         return error_mark_node;
+                       }
                      if (permerror (DECL_SOURCE_LOCATION (newdecl),
                                     "new declaration %q#D ambiguates built-in"
                                     " declaration %q#D", newdecl, olddecl)
                          && flag_permissive)
                        inform (DECL_SOURCE_LOCATION (newdecl),
                                "ignoring the %q#D declaration", newdecl);
-                     return olddecl;
+                     return flag_permissive ? olddecl : error_mark_node;
                    }
                }
 
index c518ebeff22b4e2d761fd0152dc2af64cf554f6b..a06dc24703a25ea5126903dbcdc333b14d837b2f 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-13  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/84843
+       * g++.dg/ext/pr84843-1.C: New test.
+       * g++.dg/ext/pr84843-2.C: New test.
+
 2018-03-13  David Pagan  <dave.pagan@oracle.com>
 
        PR c/46921
diff --git a/gcc/testsuite/g++.dg/ext/pr84843-1.C b/gcc/testsuite/g++.dg/ext/pr84843-1.C
new file mode 100644 (file)
index 0000000..050d3e5
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/84843
+// { dg-do compile }
+// { dg-options "-fpermissive" }
+
+extern "C" int
+__atomic_compare_exchange (int x, int y)       // { dg-error "ambiguates built-in declaration" }
+{
+  return x + y;
+}
diff --git a/gcc/testsuite/g++.dg/ext/pr84843-2.C b/gcc/testsuite/g++.dg/ext/pr84843-2.C
new file mode 100644 (file)
index 0000000..adf92fa
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/84843
+// { dg-do compile }
+// { dg-options "" }
+
+extern "C" int
+__atomic_compare_exchange (int x, int y)       // { dg-error "ambiguates built-in declaration" }
+{
+  return x + y;
+}