This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Any way to get g++ to warn about missing return in main


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]