This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Any way to get g++ to warn about missing return in main
- From: Bill Priest <priestwilliaml at yahoo dot com>
- To: "John Love-Jensen" <eljay at adobe dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 11 Jan 2002 12:57:56 -0600
- Subject: Re: Any way to get g++ to warn about missing return in main
- References: <20011227031728.16823.qmail@sources.redhat.com><20020111115757.5cd2acfc.priestwilliaml@yahoo.com><00d801c19aca$4a838890$2c01a8c0@mneljaypc>
On Fri, 11 Jan 2002 12:03:35 -0600
"John Love-Jensen" <eljay@adobe.com> wrote:
> Hi Bill,
>
> I assume your second example was supposed to be "g++ ..." instead of "gcc
> ...".
Actually since the extension is .cc it uses g++ by default.
>
> As per the C++ specification, it is legal and valid C++ code to have main()
> drop off the end without a return. The compiler is burdened with putting an
> implicit "return 0;" in the code on the (lazy) programmer's behalf.
I understand that it is legal C++ code; I'd just like for g++ to warn about it
just like gcc does IFF I set a compiler switch warning to catch it (ie. it seems
like -Wmain-return-type).
Of course for this simple example I gave it is obvious that the compiler adding
a return of is is correct; this might not always be the case and without an
explicit statement in the code the compiler can't be sure that is what I intended.
I'm not looking to change the semantics of inserting the default; I'm just looking
for a way for me to be reminded that it is missing in case I don't want the default.
Thanks for the response,
Bill
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com