Using -Wall and -Woverloaded-virtual together changes the behaviour of the code

Mathieu Malaterre malat@debian.org
Tue Mar 27 14:49:00 GMT 2018


Hi Vadim,

On Tue, Mar 27, 2018 at 3:26 PM, Vadim Zeitlin <vz-gcc@zeitlins.org> wrote:
> On Tue, 27 Mar 2018 15:08:31 +0200 Mason <slash.tmp@free.fr> wrote:
>
> M> On 23/03/2018 18:47, Vadim Zeitlin wrote:
> M>
> M> > I'm running into a rather crazy problem that I can't minimize enough to
> M> > create a bug report for, so I'd like to ask here if anybody might have any
> M> > ideas about it by chance. The problem is that the behaviour of some piece
> M> > of C++ code changes, when compiling using MinGW g++ 7.2 (20180123 version
> M> > from Debian Buster) and "-O2", depending on whether both of -Wall and
> M> > -Woverloaded-virtual command line options are specified or not.
> M>
> M> That is an interesting problem ^_^
>
>  That's a polite way of putting it :-)
>
> M> I wanted to try reproducing, but it seems that Ubuntu only packages old
> M> versions of mingw-w64 (6.3 in 17.10; 5.3 in 16.04 LTS)
> M>
> M> Do you know if your issue occurs with older versions of mingw-w64?
>
>  No, I don't think so. We did use 6.3 for this project before and didn't
> have any such problems with it and my test case works just fine with it
> too.
>
> M> In my opinion, if the problem does not occur on "vanilla" gcc, then
> M> the issue might lie with the mingw-w64 specific bits.
>
>  It seems it's even worse than that as mingw-w64 from Fedora doesn't seem
> to have any problems with the test case neither. So it might be a Debian
> problem, and not a gcc one, after all. But looking at Debian-specific
> changes at
>
> https://anonscm.debian.org/cgit/collab-maint/gcc-mingw-w64.git/tree/debian/patches/
>
> I really don't see anything even remotely related, so I still have no idea
> what's going on here.

Using a mixed stretch with g++-mingw-w64-i686/sid here is what I see:

$ i686-w64-mingw32-g++ -c -std=c++17 -O2 -Wnonnull
-Woverloaded-virtual -v 16795.cpp -o warn.o
Using built-in specs.
COLLECT_GCC=i686-w64-mingw32-g++
Target: i686-w64-mingw32
Configured with: ../../src/configure --build=x86_64-linux-gnu
--prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man'
--infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var
--disable-silent-rules --libdir='/usr/lib/x86_64-linux-gnu'
--libexecdir='/usr/lib/x86_64-linux-gnu' --disable-maintainer-mode
--disable-dependency-tracking --prefix=/usr --enable-shared
--enable-static --disable-multilib --with-system-zlib
--libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib
--enable-libstdcxx-time=yes --with-tune=generic
--with-headers=/usr/i686-w64-mingw32/include
--enable-version-specific-runtime-libs --enable-fully-dynamic-string
--enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++,ada
--enable-lto --with-plugin-ld --enable-threads=win32
--program-suffix=-win32 --program-prefix=i686-w64-mingw32-
--target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as
--with-ld=/usr/bin/i686-w64-mingw32-ld --enable-libatomic
--enable-libstdcxx-filesystem-ts=yes
Thread model: win32
gcc version 7.2-win32 20180123 (GCC)
COLLECT_GCC_OPTIONS='-c' '-std=c++1z' '-O2' '-Wnonnull'
'-Woverloaded-virtual' '-v' '-o' 'warn.o' '-shared-libgcc'
'-mtune=generic' '-march=pentiumpro'
 /usr/lib/gcc/i686-w64-mingw32/7.2-win32/cc1plus -quiet -v
-U_REENTRANT 16795.cpp -quiet -dumpbase 16795.cpp -mtune=generic
-march=pentiumpro -auxbase-strip warn.o -O2 -Wnonnull
-Woverloaded-virtual -std=c++1z -version -o /tmp/cc9O6U4l.s
GNU C++14 (GCC) version 7.2-win32 20180123 (i686-w64-mingw32)
compiled by GNU C version 7.2.0, GMP version 6.1.2, MPFR version
4.0.1-rc1, MPC version 1.1.0, isl version isl-0.18-GMP

warning: MPFR header version 4.0.1-rc1 differs from library version 4.0.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
"/usr/lib/gcc/i686-w64-mingw32/7.2-win32/../../../../i686-w64-mingw32/sys-include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i686-w64-mingw32/7.2-win32/include/c++
 /usr/lib/gcc/i686-w64-mingw32/7.2-win32/include/c++/i686-w64-mingw32
 /usr/lib/gcc/i686-w64-mingw32/7.2-win32/include/c++/backward
 /usr/lib/gcc/i686-w64-mingw32/7.2-win32/include
 /usr/lib/gcc/i686-w64-mingw32/7.2-win32/include-fixed
 /usr/lib/gcc/i686-w64-mingw32/7.2-win32/../../../../i686-w64-mingw32/include
End of search list.
GNU C++14 (GCC) version 7.2-win32 20180123 (i686-w64-mingw32)
compiled by GNU C version 7.2.0, GMP version 6.1.2, MPFR version
4.0.1-rc1, MPC version 1.1.0, isl version isl-0.18-GMP

warning: MPFR header version 4.0.1-rc1 differs from library version 4.0.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 4c0706b346120c11493ae8cc1ecc0022
16795.cpp: In function ‘unsigned int _get_output_format()’:
16795.cpp:316:25: warning: ‘unsigned int _get_output_format()’
redeclared without dllimport attribute: previous dllimport ignored
[-Wattributes]
 extern "C" unsigned int _get_output_format(void) {return 1;}
                         ^~~~~~~~~~~~~~~~~~
COLLECT_GCC_OPTIONS='-c' '-std=c++1z' '-O2' '-Wnonnull'
'-Woverloaded-virtual' '-v' '-o' 'warn.o' '-shared-libgcc'
'-mtune=generic' '-march=pentiumpro'
 /usr/bin/i686-w64-mingw32-as -v -o warn.o /tmp/cc9O6U4l.s
GNU assembler version 2.28 (i686-w64-mingw32) using BFD version (GNU
Binutils) 2.28
COMPILER_PATH=/usr/lib/gcc/i686-w64-mingw32/7.2-win32/:/usr/lib/gcc/i686-w64-mingw32/7.2-win32/:/usr/lib/gcc/i686-w64-mingw32/:/usr/lib/gcc/i686-w64-mingw32/7.2-win32/:/usr/lib/gcc/i686-w64-mingw32/:/usr/lib/gcc/i686-w64-mingw32/7.2-win32/../../../../i686-w64-mingw32/bin/
LIBRARY_PATH=/usr/lib/gcc/i686-w64-mingw32/7.2-win32/:/usr/lib/gcc/i686-w64-mingw32/7.2-win32/../../../../i686-w64-mingw32/lib/../lib/:/usr/lib/gcc/i686-w64-mingw32/7.2-win32/../../../../i686-w64-mingw32/lib/
COLLECT_GCC_OPTIONS='-c' '-std=c++1z' '-O2' '-Wnonnull'
'-Woverloaded-virtual' '-v' '-o' 'warn.o' '-shared-libgcc'
'-mtune=generic' '-march=pentiumpro'

And then:

$ objdump -d warn.o  | grep -A 2 test_main
000001a0 <__Z9test_mainiPPc>:
 1a0: 31 c0                xor    %eax,%eax
 1a2: c3                    ret

So I suspect the difference is rather in binutils, mine is still:

GNU assembler version 2.28 (i686-w64-mingw32) using BFD version (GNU
Binutils) 2.28

2cts



More information about the Gcc-help mailing list