https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85091
--- Comment #6 from Vadim Zeitlin <vz-gcc at zeitlins dot org> --- (In reply to Jonathan Wakely from comment #4) > I can't reproduce this with: > gcc version 7.2.0 20170814 (Fedora MinGW 7.2.0-1.fc26) (GCC) Thanks for testing! So this would seem to indicate that the problem is in the Debian build of the (cross)compiler only, but looking at the Debian-specific patches at https://anonscm.debian.org/cgit/collab-maint/gcc-mingw-w64.git/tree/debian/patches/ I don't see anything that could be even remotely related to this problem, so I still have no idea how is this possible. > I get one warning: > > $ i686-w64-mingw32-g++ -c -std=c++17 -Wnonnull -Woverloaded-virtual -O2 > 16795.cpp > 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;} > ^~~~~~~~~~~~~~~~~~ Yes, I get this warning too, but it's harmless (IMO it's a bug in MinGW-w64 headers, but it's a completely unrelated problem). > But no different code depending on the warning options used. To answer the comment #5 too: I do get different output (both with the initial, real, program, and this test case) just depending on whether the warnings options are used or not. The subdirectory part is a twist on top of that: if I move the file to a subdirectory, then it compiles correctly even when using the warning options. But the real problem is that just adding the warning options to the command line changes the generated code (and breaks it).