]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Disable deprecated/unavailable diagnostics when creating thunks for methods...
authorJakub Jelinek <jakub@redhat.com>
Thu, 12 Sep 2024 16:22:21 +0000 (18:22 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 13 Jun 2025 11:34:46 +0000 (13:34 +0200)
On the following testcase, we emit false positive warnings/errors about using
the deprecated or unavailable methods when creating thunks for them, even
when nothing (in the testcase so far) actually used those.

The following patch temporarily disables that diagnostics when creating
the thunks.

2024-09-12  Jakub Jelinek  <jakub@redhat.com>

PR c++/116636
* method.cc: Include decl.h.
(use_thunk): Temporarily change deprecated_state to
UNAVAILABLE_DEPRECATED_SUPPRESS.

* g++.dg/warn/deprecated-19.C: New test.

(cherry picked from commit 4026d89d623e322920b052f7ac0d940ef267dc0f)

gcc/cp/method.cc
gcc/testsuite/g++.dg/warn/deprecated-19.C [new file with mode: 0644]

index be9406e3303933ef42915ae111652e859d86726c..9e18df44f5a4458c4a8c5a394bb8a11d480b0e04 100644 (file)
@@ -26,6 +26,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "target.h"
 #include "cp-tree.h"
+#include "decl.h"
 #include "stringpool.h"
 #include "cgraph.h"
 #include "varasm.h"
@@ -283,6 +284,11 @@ use_thunk (tree thunk_fndecl, bool emit_p)
   /* Thunks are always addressable; they only appear in vtables.  */
   TREE_ADDRESSABLE (thunk_fndecl) = 1;
 
+  /* Don't diagnose deprecated or unavailable functions just because they
+     have thunks emitted for them.  */
+  auto du = make_temp_override (deprecated_state,
+                                UNAVAILABLE_DEPRECATED_SUPPRESS);
+
   /* Figure out what function is being thunked to.  It's referenced in
      this translation unit.  */
   TREE_ADDRESSABLE (function) = 1;
diff --git a/gcc/testsuite/g++.dg/warn/deprecated-19.C b/gcc/testsuite/g++.dg/warn/deprecated-19.C
new file mode 100644 (file)
index 0000000..e49af4f
--- /dev/null
@@ -0,0 +1,22 @@
+// PR c++/116636
+// { dg-do compile { target c++11 } }
+// { dg-options "-pedantic -Wdeprecated" }
+
+struct A {
+  virtual int foo () = 0;
+};
+struct B : virtual A {
+  [[deprecated]] int foo () { return 0; }      // { dg-message "declared here" }
+};
+struct C : virtual A {
+  [[gnu::unavailable]] int foo () { return 0; }        // { dg-message "declared here" }
+};
+
+void
+bar ()
+{
+  B b;
+  b.foo ();                                    // { dg-warning "'virtual int B::foo\\\(\\\)' is deprecated" }
+  C c;
+  c.foo ();                                    // { dg-error "'virtual int C::foo\\\(\\\)' is unavailable" }
+}