https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91011
Bug ID: 91011 Summary: g++ -Q --help=warning,c++ outputs from C point of view Product: gcc Version: 7.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: adam.f.badura at gmail dot com Target Milestone: --- My g++ -v outputs > Using built-in specs. > COLLECT_GCC=g++ > COLLECT_LTO_WRAPPER=/opt/gcc/x86_64/7.3.0a-1/libexec/gcc/x86_64-redhat-linux/7.3.0/lto-wrapper > Target: x86_64-redhat-linux > Configured with: ../configure --prefix=/opt/gcc/x86_64/7.3.0a-1 > --exec-prefix=/opt/gcc/x86_64/7.3.0a-1 --bindir=/opt/gcc/x86_64/7.3.0a-1/bin > --sbindir=/opt/gcc/x86_64/7.3.0a-1/sbin > --sysconfdir=/opt/gcc/x86_64/7.3.0a-1/etc > --datadir=/opt/gcc/x86_64/7.3.0a-1/share > --includedir=/opt/gcc/x86_64/7.3.0a-1/include > --libdir=/opt/gcc/x86_64/7.3.0a-1/lib > --libexecdir=/opt/gcc/x86_64/7.3.0a-1/libexec --localstatedir=/var > --sharedstatedir=/var/lib --mandir=/opt/gcc/x86_64/7.3.0a-1/man > --infodir=/opt/gcc/x86_64/7.3.0a-1/info > --with-docdir=/opt/gcc/x86_64/7.3.0a-1/doc --enable-shared > --enable-languages=c,c++ --enable-threads=posix --enable-checking=release > --with-system-zlib --disable-libunwind-exceptions --enable-libssp > --enable-lto --with-gnu-ld --verbose --disable-gtktest > --target=x86_64-redhat-linux --build=x86_64-redhat-linux > --host=x86_64-redhat-linux --enable-__cxa_atexit > Thread model: posix > gcc version 7.3.0 (GCC) however, I have seen this issue also with other versions as well. The problem is that the command > g++ -Q --help=warning,c++ outputs warnings from the C point of view rather than C++ point of view. So, executing the: > g++ -Wnon-virtual-dtor -Q --help=warning,c++ will output to the standard error stream a message > cc1: warning: command line option ‘-Wnon-virtual-dtor’ is valid for > C++/ObjC++ but not for C while the warning will still show as disabled on the output: > -Wnon-virtual-dtor [disabled] Using -x option: > g++ -Wnon-virtual-dtor -Q --help=warning,c++ -x c++ doesn't help. Exploring various versions of GCC on the Compiler Explorer (https://godbolt.org/) it seems this behavior applies to all newer versions up to 9.1 (top at the moment) and all older versions down to 5.1 and perhaps even older (I didn't check them). However, as it comes to trunk version a workaround exists. If a C++ source file is added to the command like this: > touch dummy.cpp > g++ -Wnon-virtual-dtor -Q --help=warning,c++ dummy.cpp or this: > touch dummy.whatever > g++ -Wnon-virtual-dtor -Q --help=warning,c++ -x c++ dummy.whatever it enforces C++ language perspective and the problem disappears. Sadly, the file must exist even though it is not really used for anything. If the file doesn't exist we only get: > g++: error: dummy.cc: No such file or directory Is there any workaround for versions older than trunk?