[RFC] Deprecate "implicit int" for main() in C++
Jonathan Wakely
jwakely@redhat.com
Wed Apr 25 13:12:00 GMT 2018
G++ allows the 'main' function to be declared without a return type:
$ gcc-8 -x c++ - <<< 'main() { }'
<stdin>:1:6: warning: ISO C++ forbids declaration of âmainâ with no type [-Wreturn-type]
We enabled -Wreturn-type by default in GCC 8, so code using the
extension will get warnings even without -Wall now. Users might want
to use -Werror=return-type to ensure they aren't bitten by the new
optimizations that assume control never reaches the end of a non-void
function.
Should we deprecate the "implicit int" extension for GCC 9?
Deprecating it wouldn't mean we have to remove it any time soon, and
it could still be allowed by -fpermissive.
N.B. we also allow "implicit int" in system headers, which we might
need to continue doing because some OS headers are not C++-aware, and
users can't fix their OS headers. That isn't true for 'main' because
users control that, and can fix it, and fixing it has no downside.
More information about the Gcc
mailing list