===================================================================
@@ -1837,7 +1837,8 @@ diagnose_mismatched_decls (tree newdecl, tree oldd
locate_old_decl (olddecl);
}
else if (TREE_PUBLIC (newdecl))
- warning (0, "built-in function %q+D declared as non-function",
+ warning (OPT_Wbuiltin_declaration_mismatch,
+ "built-in function %q+D declared as non-function",
newdecl);
else
warning (OPT_Wshadow, "declaration of %q+D shadows "
===================================================================
@@ -1431,7 +1431,15 @@ duplicate_decls (tree newdecl, tree olddecl, bool
/* Avoid warnings redeclaring built-ins which have not been
explicitly declared. */
if (DECL_ANTICIPATED (olddecl))
- return NULL_TREE;
+ {
+ if (TREE_PUBLIC (newdecl)
+ && CP_DECL_CONTEXT (newdecl) == global_namespace)
+ warning_at (DECL_SOURCE_LOCATION (newdecl),
+ OPT_Wbuiltin_declaration_mismatch,
+ "built-in function %qD declared as non-function",
+ newdecl);
+ return NULL_TREE;
+ }
/* If you declare a built-in or predefined function name as static,
the old definition is overridden, but optionally warn this was a
@@ -1522,7 +1530,7 @@ next_arg:;
warning_at (DECL_SOURCE_LOCATION (newdecl),
OPT_Wbuiltin_declaration_mismatch,
- "declaration of %q+#D conflicts with built-in "
+ "declaration of %q#D conflicts with built-in "
"declaration %q#D", newdecl, olddecl);
}
else if ((DECL_EXTERN_C_P (newdecl)
===================================================================
@@ -6313,7 +6313,8 @@ attributes.
@item -Wno-builtin-declaration-mismatch
@opindex Wno-builtin-declaration-mismatch
@opindex Wbuiltin-declaration-mismatch
-Warn if a built-in function is declared with the wrong signature.
+Warn if a built-in function is declared with the wrong signature or
+as non-function.
This warning is enabled by default.
@item -Wno-builtin-macro-redefined
===================================================================
@@ -0,0 +1,4 @@
+/* PR c++/82466 */
+/* { dg-options "-Wbuiltin-declaration-mismatch" } */
+
+int printf; /* { dg-warning "declared as non-function" } */
===================================================================
@@ -0,0 +1,4 @@
+/* PR c++/82466 */
+/* { dg-options "-Wno-builtin-declaration-mismatch" } */
+
+int printf;
===================================================================
@@ -1,5 +1,5 @@
// PR c++/14432
-// { dg-options "" }
+// { dg-options "-Wno-builtin-declaration-mismatch" }
struct Y {};
Y y1;
===================================================================
@@ -0,0 +1,7 @@
+// PR c++/82466
+// { dg-options "-Wbuiltin-declaration-mismatch" }
+
+namespace N
+{
+ int printf;
+}
===================================================================
@@ -1,5 +1,5 @@
// { dg-do assemble }
-// { dg-options "" }
+// { dg-options "-Wno-builtin-declaration-mismatch" }
// This test case caused the compiler to abort at one point in time.
// prms-id: 811