Bug 65974 - [5/6 Regression] Bogus deprecated-declarations warnings for inline definitions of deprecated virtual methods
Summary: [5/6 Regression] Bogus deprecated-declarations warnings for inline definition...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.1.1
: P3 normal
Target Milestone: 5.3
Assignee: Jason Merrill
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2015-05-02 01:19 UTC by Vadim Zeitlin
Modified: 2015-08-17 14:26 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.9.3
Known to fail: 5.1.0, 5.2.0, 6.0
Last reconfirmed: 2015-07-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vadim Zeitlin 2015-05-02 01:19:34 UTC
Consider the following example:

	% cat -n deprdecl.cpp
	     1  struct S {
	     2      void bar();
	     3
	     4      __attribute__((deprecated("use bar() instead.")))
	     5      virtual void foo();
	     6  };
	     7
	     8  inline void S::foo() { bar(); }
	     9
	    10  int main()
	    11  {
	    12      return 0;
	    13  }
	% g++-5 -c -Wall deprdecl.cpp
	deprdecl.cpp:13:1: warning: 'virtual void S::foo()' is deprecated: use bar() instead. [-Wdeprecated-declarations]
	 }
	 ^
	deprdecl.cpp:8:13: note: declared here
	 inline void S::foo() { bar(); }
		     ^

I believe this warning shouldn't appear when the deprecated method is just being defined and not used. Notice that it indeed does not appear if the method is either not virtual (i.e. remove "virtual" in line 5) or is defined inline (i.e. move the body from line 8 to line 5). Nor does it appear with 4.9.

Also notice that the warning location is always the last line of the last function in the file and has nothing to do with the function it complains about.

This warning may look like not a big deal, but when compiling my real code it occurs many thousands times making it impossible to use deprecated attribute with g++ 5.1.

Compiler information:

	% g++-5 -v
	Using built-in specs.
	COLLECT_GCC=g++-5
	COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
	Target: x86_64-linux-gnu
	Configured with: ../src/configure -v --with-pkgversion='Debian 5.1.1-2' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=c++11 --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --with-arch-32=i586 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
	Thread model: posix
	gcc version 5.1.1 (Debian 5.1.1-2)
Comment 1 Neil Bird 2015-07-06 07:35:54 UTC
I am also seeing this, although I don't have to put anything inline.  When compiling C++, I get a warning flagged at the end of each class's .cpp for every member declared deprecated in the header, even if it's not used (the bodies for those routines being in the .cpp).

# Scientific Linux 6.4, 32-bit
$ gcc51 -v
Using built-in specs.
COLLECT_GCC=gcc51
COLLECT_LTO_WRAPPER=/opt/libexec/gcc/i686-pc-linux-gnu/5.1.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../gcc-5.1.0/configure --prefix=/opt --program-suffix=51 --enable-languages=c,c++ --with-isl=/opt
Thread model: posix
gcc version 5.1.0 (GCC)
Comment 2 Richard Biener 2015-07-27 08:03:47 UTC
Confirmed.
Comment 3 Jason Merrill 2015-08-15 07:59:58 UTC
Author: jason
Date: Sat Aug 15 07:59:26 2015
New Revision: 226908

URL: https://gcc.gnu.org/viewcvs?rev=226908&root=gcc&view=rev
Log:
	PR c++/65974
	* decl2.c (mark_vtable_entries): Suppress -Wdeprecated.

Added:
    trunk/gcc/testsuite/g++.dg/warn/deprecated-9.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl2.c
Comment 4 Jason Merrill 2015-08-15 08:00:11 UTC
Author: jason
Date: Sat Aug 15 07:59:39 2015
New Revision: 226909

URL: https://gcc.gnu.org/viewcvs?rev=226909&root=gcc&view=rev
Log:
	PR c++/65974
	* decl2.c (mark_vtable_entries): Suppress -Wdeprecated.

Added:
    branches/gcc-5-branch/gcc/testsuite/g++.dg/warn/deprecated-9.C
Modified:
    branches/gcc-5-branch/gcc/cp/ChangeLog
    branches/gcc-5-branch/gcc/cp/decl2.c
Comment 5 Jason Merrill 2015-08-17 14:26:56 UTC
Fixed.