https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79746
Bug ID: 79746 Summary: Confusing -Wunused-but-set-parameter warning with virtual inheritance Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sgunderson at bigfoot dot com Target Milestone: --- Hi, This is a minified testcase of MySQL when trying to compile with a 7.0 snapshot: atum17:~> /usr/lib/gcc-snapshot/bin/g++ -v Using built-in specs. COLLECT_GCC=/usr/lib/gcc-snapshot/bin/g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc-snapshot/libexec/gcc/x86_64-linux-gnu/7/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 20170226-1' --with-bugurl=file:///usr/share/doc/gcc-snapshot/README.Bugs --enable-languages=c,ada,c++,go,brig,fortran,objc,obj-c++ --prefix=/usr/lib/gcc-snapshot --with-gcc-major-version-only --program-prefix= --enable-shared --enable-linker-build-id --disable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=yes --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 7.0.1 20170226 (experimental) [trunk revision 245744] (Debian 20170226-1) atum17:~> cat test2.cc struct Base { Base(const char *foo) : m_foo(foo) {} virtual int func() = 0; const char *m_foo; }; struct Derived : public virtual Base { Derived(const char *foo) : Base(foo) {} }; atum17:~> /usr/lib/gcc-snapshot/bin/g++ -Wunused-but-set-parameter -c test2.cc test2.cc: In constructor 'Derived::Derived(const char*)': test2.cc:9:22: warning: parameter 'foo' set but not used [-Wunused-but-set-parameter] Derived(const char *foo) : Base(foo) {} I think the warning is actually somehow correct, but it's very confusing until you see what's going on. I think the logic goes something like: Virtual bases are always set through the most derived class. Since Derived has a pure virtual (func()), it can't be the most derived class, and thus, its call to Base() can never actually happen. Thus, “foo” is unused. Perhaps a better warning would be something like test2.cc:9:22: warning: class 'Derived' inherits virtually from 'Base' but is not possible to instantiate by itself, so it can never be the most derived class, and the call to 'Base::Base(const char *foo)' is always ignored but that might be too wordy.