This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[RFC] Deprecate "implicit int" for main() in C++
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 25 Apr 2018 13:23:05 +0100
- Subject: [RFC] Deprecate "implicit int" for main() in C++
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.