re PR c++/82466 (Missing warning for re-declaration of built-in function as variable)
authorPaolo Carlini <paolo@gcc.gnu.org>
Tue, 24 Oct 2017 19:01:03 +0000 (19:01 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 24 Oct 2017 19:01:03 +0000 (19:01 +0000)
2017-10-24  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/82466
* doc/invoke.texi ([Wbuiltin-declaration-mismatch]): Extend
description.

/cp
2017-10-24  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/82466
* decl.c (duplicate_decls): Warn for built-in functions declared as
non-function, use OPT_Wbuiltin_declaration_mismatch.

* decl.c (duplicate_decls): Avoid redundant '+' in warning_at.

/c
2017-10-24  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/82466
* c-decl.c (diagnose_mismatched_decls): Use
OPT_Wbuiltin_declaration_mismatch.

/testsuite
2017-10-24  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/82466
* c-c++-common/Wbuiltin-declaration-mismatch-1.c: New.
* c-c++-common/Wno-builtin-declaration-mismatch-1.c: Likewise.
* g++.dg/warn/Wbuiltin_declaration_mismatch-1.C: Likewise.
* g++.dg/parse/builtin2.C: Adjust.
* g++.old-deja/g++.mike/p811.C: Likewise.

From-SVN: r254057

12 files changed:
gcc/ChangeLog
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Wbuiltin-declaration-mismatch-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wno-builtin-declaration-mismatch-1.c [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/builtin2.C
gcc/testsuite/g++.dg/warn/Wbuiltin_declaration_mismatch-1.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.mike/p811.C

index e0ef3edb9da2663cf7ab89fec5987d61288a1eb3..a27df40cd624ef6fbf92598c9609ea22f41021bd 100644 (file)
@@ -1,3 +1,9 @@
+2017-10-24  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/82466
+       * doc/invoke.texi ([Wbuiltin-declaration-mismatch]): Extend
+       description.
+
 2017-10-24  Wilco Dijkstra  <wdijkstr@arm.com>
 
        PR rtl-optimization/82396
@@ -55,7 +61,7 @@
        * tree-outof-ssa.h (always_initialized_rtx_for_ssa_name_p): Delete.
        * expr.c (expand_expr_real_1) <expand_decl_rtl>: Revert latest change.
        * loop-iv.c (iv_get_reaching_def): Likewise.
-       * cfgexpand.c (expand_one_ssa_partition): Initialize the RTX if the 
+       * cfgexpand.c (expand_one_ssa_partition): Initialize the RTX if the
        variable is promoted and the partition contains undefined values.
 
 2017-10-23  Sandra Loosemore  <sandra@codesourcery.com>
@@ -76,7 +82,7 @@
        (nios2_symbolic_constant_allowed): New.
        (nios2_symbolic_constant_p): New.
        (nios2_plus_symbolic_constant_p): New.
-       (nios2_valid_addr_expr_p): Recognize addresses involving 
+       (nios2_valid_addr_expr_p): Recognize addresses involving
        symbolic constants.
        (nios2_legitimate_address_p): Likewise, also LO_SUM.
        (nios2_symbolic_memory_operand_p): New.
        * i386.h (processor_costs): Remove sse_move; add xmm_move, ymm_move
        and zmm_move. Increase size of sse load and store tables;
        add unaligned load and store tables; add ssemmx_to_integer.
-       * x86-tune-costs.h: Update all entries according to real 
+       * x86-tune-costs.h: Update all entries according to real
        move latencies from Agner Fog's manual and chip documentation.
 
 2017-10-23  Jakub Jelinek  <jakub@redhat.com>
index 1f697f17f9924982ccad43f23e78ad48fd656a16..c260f62b11166edd133d7f8a95e7fac3f35e1ba9 100644 (file)
@@ -1,3 +1,9 @@
+2017-10-24  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/82466
+       * c-decl.c (diagnose_mismatched_decls): Use
+       OPT_Wbuiltin_declaration_mismatch.
+
 2017-10-12  David Malcolm  <dmalcolm@redhat.com>
 
        * c-parser.c (c_parser_require): Add "type_is_unique" param and
index 26b34ab3e50ab461fb7a228688c42895345ff4fc..5c472e66af8b363e63c0702e94a23c0a35861f0a 100644 (file)
@@ -1837,7 +1837,8 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
          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 "
index e24a1949d867cf1bb3f708364c8b45cf4bac237b..8c587a3e845db17ee925ede0d725fbaec00ac613 100644 (file)
@@ -1,3 +1,11 @@
+2017-10-24  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/82466
+       * decl.c (duplicate_decls): Warn for built-in functions declared as
+       non-function, use OPT_Wbuiltin_declaration_mismatch.
+
+       * decl.c (duplicate_decls): Avoid redundant '+' in warning_at.
+
 2017-10-24  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/80991
index a3cc80cf7a30f5e95e5cde876a114131da3d6511..bb48099da56cede342d430006726ddb906b1f153 100644 (file)
@@ -1431,7 +1431,15 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
          /* 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)
index 3a879566487e2d12ce4634364d877d38848c10de..71b2445f70fd5b832c68c08e69e71d8ecad37a4a 100644 (file)
@@ -6320,7 +6320,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
index edf21e9e8b8597542442700ad8ffc4f75e68ed54..7801c03d1d3f8a832de9dfec6648db8159b7a645 100644 (file)
@@ -1,3 +1,12 @@
+2017-10-24  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/82466
+       * c-c++-common/Wbuiltin-declaration-mismatch-1.c: New.
+       * c-c++-common/Wno-builtin-declaration-mismatch-1.c: Likewise.
+       * g++.dg/warn/Wbuiltin_declaration_mismatch-1.C: Likewise.
+       * g++.dg/parse/builtin2.C: Adjust.
+       * g++.old-deja/g++.mike/p811.C: Likewise.
+
 2017-10-24  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/80991
diff --git a/gcc/testsuite/c-c++-common/Wbuiltin-declaration-mismatch-1.c b/gcc/testsuite/c-c++-common/Wbuiltin-declaration-mismatch-1.c
new file mode 100644 (file)
index 0000000..63343b8
--- /dev/null
@@ -0,0 +1,4 @@
+/* PR c++/82466 */
+/* { dg-options "-Wbuiltin-declaration-mismatch" } */
+
+int printf;  /* { dg-warning "declared as non-function" } */
diff --git a/gcc/testsuite/c-c++-common/Wno-builtin-declaration-mismatch-1.c b/gcc/testsuite/c-c++-common/Wno-builtin-declaration-mismatch-1.c
new file mode 100644 (file)
index 0000000..6409412
--- /dev/null
@@ -0,0 +1,4 @@
+/* PR c++/82466 */
+/* { dg-options "-Wno-builtin-declaration-mismatch" } */
+
+int printf;
index c524ea68416bfd4916a8fbac4bdc2891cdbf3bda..daa80bb11b02ea3c236d46ea63a63be615cd3999 100644 (file)
@@ -1,5 +1,5 @@
 // PR c++/14432
-// { dg-options "" }
+// { dg-options "-Wno-builtin-declaration-mismatch" }
 
 struct Y {}; 
 Y y1; 
diff --git a/gcc/testsuite/g++.dg/warn/Wbuiltin_declaration_mismatch-1.C b/gcc/testsuite/g++.dg/warn/Wbuiltin_declaration_mismatch-1.C
new file mode 100644 (file)
index 0000000..713073c
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/82466
+// { dg-options "-Wbuiltin-declaration-mismatch" }
+
+namespace N
+{
+  int printf;
+}
index 5c8260aa1f8ae6b8b2dbbf745e35fabe9b997b00..2ca04abdcba79a7015156b268e222bd90e56987b 100644 (file)
@@ -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