+2018-03-09 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/84724
+ * decl.c (duplicate_decls): Don't override __* prefixed builtins
+ except for __[^b]*_chk, instead issue permerror and for -fpermissive
+ also a note and return olddecl.
+
2018-03-09 Nathan Sidwell <nathan@acm.org>
PR c++/84733
|| compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
{
+ /* Don't really override olddecl for __* prefixed builtins
+ except for __[^b]*_chk, the compiler might be using those
+ explicitly. */
+ if (DECL_BUILT_IN (olddecl))
+ {
+ tree id = DECL_NAME (olddecl);
+ const char *name = IDENTIFIER_POINTER (id);
+ size_t len;
+
+ if (name[0] == '_'
+ && name[1] == '_'
+ && (strncmp (name + 2, "builtin_",
+ strlen ("builtin_")) == 0
+ || (len = strlen (name)) <= strlen ("___chk")
+ || memcmp (name + len - strlen ("_chk"),
+ "_chk", strlen ("_chk") + 1) != 0))
+ {
+ 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;
+ }
+ }
+
/* A near match; override the builtin. */
if (TREE_PUBLIC (newdecl))
--- /dev/null
+// PR c++/84724
+// { dg-do compile }
+// { dg-options "-O3 -fpermissive" }
+
+int __builtin_trap (); // { dg-warning "ambiguates built-in declaration" }
+ // { dg-message "ignoring the 'int __builtin_trap\\(\\)' declaration" "" { target *-*-* } .-1 }
+
+int
+foo ()
+{
+ int b;
+ int c (&b); // { dg-warning "invalid conversion from" }
+ return b %= b ? c : 0;
+}
--- /dev/null
+// PR c++/84724
+// { dg-do compile }
+// { dg-options "-O3 -fpermissive -w" }
+
+int __builtin_trap (); // { dg-bogus "ambiguates built-in declaration" }
+ // { dg-bogus "ignoring the 'int __builtin_trap\\(\\)' declaration" "" { target *-*-* } .-1 }
+
+int
+foo ()
+{
+ int b;
+ int c (&b); // { dg-bogus "invalid conversion from" }
+ return b %= b ? c : 0;
+}