c++: Redundant -Wdeprecated-declarations warning in build_over_call [PR67960]
authorPatrick Palka <ppalka@redhat.com>
Thu, 12 Mar 2020 18:38:42 +0000 (14:38 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 13 Mar 2020 14:30:36 +0000 (10:30 -0400)
In build_over_call, we are emitting a redundant -Wdeprecated-declarations
warning about the deprecated callee function, first from mark_used and again
from build_addr_func <- decay_conversion <- cp_build_addr_expr <- mark_used.

It seems this second deprecation warning coming from build_addr_func will always
be redundant, so we can safely use a warning_sentinel to disable it before
calling build_addr_func.  (And any deprecation warning that could come from
build_addr_func would be for FN, so we wouldn't be suppressing too much.)

gcc/cp/ChangeLog:

PR c++/67960
* call.c (build_over_call): Use a warning_sentinel to disable
warn_deprecated_decl before calling build_addr_func.

gcc/testsuite/ChangeLog:

PR c++/67960
* g++.dg/diagnostic/pr67960.C: New test.
* g++.dg/diagnostic/pr67960-2.C: New test.

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/pr67960-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/pr67960.C [new file with mode: 0644]

index b94e3bb8eb20055bde8e090afd0ca5cb623e657e..eea795de2185bd139c81b3ccc8b1ad12922d2ed6 100644 (file)
@@ -1,3 +1,9 @@
+2020-03-13  Patrick Palka  <ppalka@redhat.com>
+
+       PR c++/67960
+       * call.c (build_over_call): Use a warning_sentinel to disable
+       warn_deprecated_decl before calling build_addr_func.
+
 2020-03-12  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/94124
index 5767a8b8c4e6b2fc062457ebc3ba2e95d978a662..1715acc0ec35dd003156464347255cad12608c46 100644 (file)
@@ -9062,6 +9062,11 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
     }
   else
     {
+      /* If FN is marked deprecated, then we've already issued a deprecated-use
+        warning from mark_used above, so avoid redundantly issuing another one
+        from build_addr_func.  */
+      warning_sentinel w (warn_deprecated_decl);
+
       fn = build_addr_func (fn, complain);
       if (fn == error_mark_node)
        return error_mark_node;
index 6e2099bec5a4f018c0eea64ae366d9756e02ec75..2f738fadd8019c260d37aba2fb200d0efcbffc58 100644 (file)
@@ -1,3 +1,9 @@
+2020-03-13  Patrick Palka  <ppalka@redhat.com>
+
+       PR c++/67960
+       * g++.dg/diagnostic/pr67960.C: New test.
+       * g++.dg/diagnostic/pr67960-2.C: New test.
+
 2020-03-13  Martin Liska  <mliska@suse.cz>
 
        PR lto/94157
diff --git a/gcc/testsuite/g++.dg/diagnostic/pr67960-2.C b/gcc/testsuite/g++.dg/diagnostic/pr67960-2.C
new file mode 100644 (file)
index 0000000..d2ba509
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/67960
+// { dg-do compile }
+// { dg-additional-options "-Werror -fmax-errors=1" }
+__attribute__((deprecated)) void doNothing(){}
+
+int
+main()
+{
+  doNothing(); // { dg-error "is deprecated" }
+}
+
+// { dg-message "all warnings being treated as errors" "" { target *-*-* } 0 }
+// { dg-bogus "compilation terminated" "" { target *-*-* } 0 }
diff --git a/gcc/testsuite/g++.dg/diagnostic/pr67960.C b/gcc/testsuite/g++.dg/diagnostic/pr67960.C
new file mode 100644 (file)
index 0000000..d7b1a2d
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/67960
+// { dg-do compile { target c++14 } }
+// { dg-additional-options "-Werror -fmax-errors=1" }
+[[deprecated]] void doNothing(){}
+
+int
+main()
+{
+  doNothing(); // { dg-error "is deprecated" }
+}
+
+// { dg-message "all warnings being treated as errors" "" { target *-*-* } 0 }
+// { dg-bogus "compilation terminated" "" { target *-*-* } 0 }