* Any way to get g++ to warn about missing return in main
[not found] <20011227031728.16823.qmail@sources.redhat.com>
@ 2002-01-11 10:04 ` Bill Priest
[not found] ` <00d801c19aca$4a838890$2c01a8c0@mneljaypc>
0 siblings, 1 reply; 2+ messages in thread
From: Bill Priest @ 2002-01-11 10:04 UTC (permalink / raw)
To: gcc-help
All,
Using gcc & g++ stock 3.0.3 on Linux ix86 I have the following code
t.c & t.cc
--------------
int main(void)
{
}
--------------
Using gcc -Wall -c t.c
t.c: In function `main':
t.c:3: warning: control reaches end of non-void function
Using gcc -Wall -c t.cc
No warnings
Looking at the man pages for 3.0
-Wreturn-type
Warn whenever a function is defined with a return-type that defaults to "int".
Also warn about any "return" statement with no return-value
in a function whose return-type is not "void".
For C++, a function without return type always produces a diagnostic message,
even when -Wno-return-type is specified. The only exceptions
are main and functions defined in system headers.
The second sentence in the second paragraph is a little ambiguous:
It could be read to mean that main and system headers are not checked w/ -Wno-return-type
It could be read to mean that main and system headers are not checked no matter what
Assuming that main and system headers are not checked no matter what I tried the following:
gcc -Wall -pedantic -ansi -Wmain -Wsystem-headers -Wmissing-noreturn -c t.cc
Is there any way to get missing return warnings on main from g++?
It seems inconsistent (to me) to for c++ to require a return type of int; but not get a
warning about not having a return.
My 2 cents,
Bill
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Any way to get g++ to warn about missing return in main
[not found] ` <00d801c19aca$4a838890$2c01a8c0@mneljaypc>
@ 2002-01-11 11:04 ` Bill Priest
0 siblings, 0 replies; 2+ messages in thread
From: Bill Priest @ 2002-01-11 11:04 UTC (permalink / raw)
To: John Love-Jensen; +Cc: gcc-help
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-01-11 19:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20011227031728.16823.qmail@sources.redhat.com>
2002-01-11 10:04 ` Any way to get g++ to warn about missing return in main Bill Priest
[not found] ` <00d801c19aca$4a838890$2c01a8c0@mneljaypc>
2002-01-11 11:04 ` Bill Priest
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).