diff mbox

C++ PATCH for c++/65974 (deprecated virtual)

Message ID 55CEF13D.6030409@redhat.com
State New
Headers show

Commit Message

Jason Merrill Aug. 15, 2015, 7:58 a.m. UTC
When a vtable uses a deprecated virtual function, that's outside the 
user's control and so shouldn't be warned about.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 3e78f42251b5a82bc3aa2c00b85e40abb54fc70f
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Aug 14 17:41:24 2015 +0100

    	PR c++/65974
    	* decl2.c (mark_vtable_entries): Suppress -Wdeprecated.

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index f5d1e52..b0368ae 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -1742,6 +1742,9 @@  mark_vtable_entries (tree decl)
   tree fnaddr;
   unsigned HOST_WIDE_INT idx;
 
+  /* It's OK for the vtable to refer to deprecated virtual functions.  */
+  warning_sentinel w(warn_deprecated_decl);
+
   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)),
 			      idx, fnaddr)
     {
diff --git a/gcc/testsuite/g++.dg/warn/deprecated-9.C b/gcc/testsuite/g++.dg/warn/deprecated-9.C
new file mode 100644
index 0000000..fc861ee
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/deprecated-9.C
@@ -0,0 +1,16 @@ 
+// PR c++/65974
+// { dg-options "-Wdeprecated" }
+
+struct S {
+    void bar();
+
+    __attribute__((deprecated("use bar() instead.")))
+    virtual void foo();
+};
+
+void S::foo() { bar(); }
+
+int main()
+{
+    return 0;
+}