In particular, how can g++ be made to reject this invalid-as-standard-C++ code:
main(){}
?
I'm using MinGW g++ 6.2.0, but I imagine an answer will apply to all currently used variants of g++.
Example of what I've tried:
[C:\my\temp] > g++ --version | find "++" g++ (i686-win32-dwarf-rev1, Built by MinGW-W64 project) 6.2.0 [C:\my\temp] > type foo.cpp main() {} [C:\my\temp] > dir /b foo.cpp [C:\my\temp] > g++ foo.cpp -Wall -Wextra -Wreturn-type -pedantic [C:\my\temp] > dir /b a.exe foo.cpp [C:\my\temp] > _
Version info with verbose compiler output:
C:\my\temp] > g++ -v --version Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=C:/Program\ Files\ (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../libexec/gcc/i686-w64-mingw32/6.2.0/lto-wrapper.exe g++ (i686-win32-dwarf-rev1, Built by MinGW-W64 project) 6.2.0 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Target: i686-w64-mingw32 Configured with: ../../../src/gcc-6.2.0/configure --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-sysroot=/c/mingw620/i686-620-win32-dwarf-rt_v5-rev1/mingw32 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=win32 --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-libstdcxx-filesystem-ts=yes --disable-sjlj-exceptions --with-dwarf2 --disable-isl-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tune=generic --with-libiconv --with-system-zlib --with-gmp=/c/mingw620/prerequisites/i686-w64-mingw32-static --with-mpfr=/c/mingw620/prerequisites/i686-w64-mingw32-static --with-mpc=/c/mingw620/prerequisites/i686-w64-mingw32-static --with-isl=/c/mingw620/prerequisites/i686-w64-mingw32-static --with-pkgversion='i686-win32-dwarf-rev1, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/c/mingw620/i686-620-win32-dwarf-rt_v5-rev1/mingw32/opt/include -I/c/mingw620/prerequisites/i686-zlib-static/include -I/c/mingw620/prerequisites/i686-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/c/mingw620/i686-620-win32-dwarf-rt_v5-rev1/mingw32/opt/include -I/c/mingw620/prerequisites/i686-zlib-static/include -I/c/mingw620/prerequisites/i686-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/c/mingw620/i686-620-win32-dwarf-rt_v5-rev1/mingw32/opt/lib -L/c/mingw620/prerequisites/i686-zlib-static/lib -L/c/mingw620/prerequisites/i686-w64-mingw32-static/lib -Wl,--large-address-aware' Thread model: win32 gcc version 6.2.0 (i686-win32-dwarf-rev1, Built by MinGW-W64 project) COLLECT_GCC_OPTIONS='-v' '--version' '-shared-libgcc' '-mtune=generic' '-march=i686' C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../libexec/gcc/i686-w64-mingw32/6.2.0/cc1.exe -quiet -v -iprefix C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/ -U_REENTRANT help-dummy -quiet -dumpbase help-dummy -mtune=generic -march=i686 -auxbase help-dummy -version --version -o C:\Users\AlfP\AppData\Local\Temp\cc4K0l79.s GNU C11 (i686-win32-dwarf-rev1, Built by MinGW-W64 project) version 6.2.0 (i686-w64-mingw32) compiled by GNU C version 6.2.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version 0.15 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 COLLECT_GCC_OPTIONS='-v' '--version' '-shared-libgcc' '-mtune=generic' '-march=i686' C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../i686-w64-mingw32/bin/as.exe -v --version -o C:\Users\AlfP\AppData\Local\Temp\ccn2QnTg.o C:\Users\AlfP\AppData\Local\Temp\cc4K0l79.s GNU assembler version 2.25 (i686-w64-mingw32) using BFD version (GNU Binutils) 2.25 GNU assembler (GNU Binutils) 2.25 Copyright (C) 2014 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or later. This program has absolutely no warranty. This assembler was configured for a target of `i686-w64-mingw32'. COMPILER_PATH=C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../libexec/gcc/i686-w64-mingw32/6.2.0/;C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../libexec/gcc/;C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../i686-w64-mingw32/bin/ LIBRARY_PATH=C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/;C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/;C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../i686-w64-mingw32/lib/../lib/;C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../lib/;C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../i686-w64-mingw32/lib/;C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../ COLLECT_GCC_OPTIONS='-v' '--version' '-shared-libgcc' '-mtune=generic' '-march=i686' C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../libexec/gcc/i686-w64-mingw32/6.2.0/collect2.exe -plugin C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../libexec/gcc/i686-w64-mingw32/6.2.0/liblto_plugin-0.dll -plugin-opt=C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../libexec/gcc/i686-w64-mingw32/6.2.0/lto-wrapper.exe -plugin-opt=-fresolution=C:\Users\AlfP\AppData\Local\Temp\ccXVaxln.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-liconv -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt --sysroot=C:/mingw620/i686-620-win32-dwarf-rt_v5-rev1/mingw32 -m i386pe -Bdynamic -u ___register_frame_info -u ___deregister_frame_info --version C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../i686-w64-mingw32/lib/../lib/crt2.o C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/crtbegin.o -LC:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0 -LC:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc -LC:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../i686-w64-mingw32/lib/../lib -LC:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../lib -LC:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../i686-w64-mingw32/lib -LC:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../.. C:\Users\AlfP\AppData\Local\Temp\ccn2QnTg.o -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -liconv -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/crtend.o collect2 version 6.2.0 C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../i686-w64-mingw32/bin/ld.exe -plugin C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../libexec/gcc/i686-w64-mingw32/6.2.0/liblto_plugin-0.dll -plugin-opt=C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../libexec/gcc/i686-w64-mingw32/6.2.0/lto-wrapper.exe -plugin-opt=-fresolution=C:\Users\AlfP\AppData\Local\Temp\ccXVaxln.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-liconv -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt --sysroot=C:/mingw620/i686-620-win32-dwarf-rt_v5-rev1/mingw32 -m i386pe -Bdynamic -u ___register_frame_info -u ___deregister_frame_info --version C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../i686-w64-mingw32/lib/../lib/crt2.o C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/crtbegin.o -LC:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0 -LC:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc -LC:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../i686-w64-mingw32/lib/../lib -LC:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../lib -LC:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../../../i686-w64-mingw32/lib -LC:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/../../.. C:\Users\AlfP\AppData\Local\Temp\ccn2QnTg.o -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -liconv -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt C:/Program Files (x86)/mingw-w64/i686-6.2.0-win32-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.2.0/crtend.o GNU ld (GNU Binutils) 2.25 Copyright (C) 2014 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty. COLLECT_GCC_OPTIONS='-v' '--version' '-shared-libgcc' '-mtune=generic' '-march=i686' [C:\my\temp] > _