https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63657
Bug ID: 63657 Summary: [4.9 regression] -Wunused-variable: warning supressed by virtual dtor fn Product: gcc Version: 4.9.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: petschy at gmail dot com The under code has two unused variables, which are references to classes. We should have two warnings, however 4.9.1 and 5.0 trunk gives just one. 4.7.2 and 4.8.3 are ok. The second warning is supressed by the virtual dtor in Bar. Only the dtor does the trick, if I comment it out or instead I define a plain virtual fn, the warning appears. g++-4.8 -Wunused-variable -c 20141022-unused_warn.cpp 20141022-unused_warn.cpp: In function ‘void foo()’: 20141022-unused_warn.cpp:7:7: warning: unused variable ‘f’ [-Wunused-variable] Foo& f = getfoo(); ^ 20141022-unused_warn.cpp: In function ‘void bar()’: 20141022-unused_warn.cpp:18:7: warning: unused variable ‘b’ [-Wunused-variable] Bar& b = getbar(); ^ g++-5.0.0 -Wunused-variable -c 20141022-unused_warn.cpp 20141022-unused_warn.cpp: In function ‘void foo()’: 20141022-unused_warn.cpp:7:7: warning: unused variable ‘f’ [-Wunused-variable] Foo& f = getfoo(); ^ ----8<----8<----8<---- class Foo { }; Foo& getfoo(); void foo() { Foo& f = getfoo(); } class Bar { virtual ~Bar() {} }; Bar& getbar(); void bar() { Bar& b = getbar(); }