public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/31977]  New: can return OK from "int main()" without a return statement by using a goto before the return
@ 2007-05-17 15:46 bmcfadden at cdp dot com
  2007-05-17 15:48 ` [Bug c/31977] " bmcfadden at cdp dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: bmcfadden at cdp dot com @ 2007-05-17 15:46 UTC (permalink / raw)
  To: gcc-bugs

I'm using gcc 3.4.5, and I was looking into a weird condition.  The following
program compiles OK:

#include <stdio.h>
int alloc()
{
return 0;
}
int main(int argc, char* argv[])
{
       printf("Testing!\n");
       if(alloc() == 0)goto Radhe;
       return 0;
Radhe:
         printf("Hello\n");
}

The result is a program which prints "Testing", then "Hello", and then exits. 
I and a few other people expect that the compiler would generate an error
during compile, because main should return an int, and not all code paths have
a return statement; however, both gcc and msvc are compiling this OK.

added note: this bug was recently discussed on the NTDEV mailing list.


-- 
           Summary: can return OK from "int main()" without a return
                    statement by using a goto before the return
           Product: gcc
           Version: 3.4.5
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bmcfadden at cdp dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31977


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/31977] can return OK from "int main()" without a return statement by using a goto before the return
  2007-05-17 15:46 [Bug c/31977] New: can return OK from "int main()" without a return statement by using a goto before the return bmcfadden at cdp dot com
@ 2007-05-17 15:48 ` bmcfadden at cdp dot com
  2007-05-17 15:52 ` bmcfadden at cdp dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: bmcfadden at cdp dot com @ 2007-05-17 15:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from bmcfadden at cdp dot com  2007-05-17 16:48 -------
Created an attachment (id=13571)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13571&action=view)
The file from -save-temps


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31977


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/31977] can return OK from "int main()" without a return statement by using a goto before the return
  2007-05-17 15:46 [Bug c/31977] New: can return OK from "int main()" without a return statement by using a goto before the return bmcfadden at cdp dot com
  2007-05-17 15:48 ` [Bug c/31977] " bmcfadden at cdp dot com
@ 2007-05-17 15:52 ` bmcfadden at cdp dot com
  2007-05-17 15:54 ` bmcfadden at cdp dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: bmcfadden at cdp dot com @ 2007-05-17 15:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bmcfadden at cdp dot com  2007-05-17 16:52 -------
Created an attachment (id=13572)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13572&action=view)
the assembly (.s) file


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31977


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/31977] can return OK from "int main()" without a return statement by using a goto before the return
  2007-05-17 15:46 [Bug c/31977] New: can return OK from "int main()" without a return statement by using a goto before the return bmcfadden at cdp dot com
  2007-05-17 15:48 ` [Bug c/31977] " bmcfadden at cdp dot com
  2007-05-17 15:52 ` bmcfadden at cdp dot com
@ 2007-05-17 15:54 ` bmcfadden at cdp dot com
  2007-05-17 17:53 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: bmcfadden at cdp dot com @ 2007-05-17 15:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from bmcfadden at cdp dot com  2007-05-17 16:54 -------
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.5/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.5 20051201 (Red Hat 3.4.5-2)


-- 

bmcfadden at cdp dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bmcfadden at cdp dot com
   GCC host triplet|                            |i386-redhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31977


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/31977] can return OK from "int main()" without a return statement by using a goto before the return
  2007-05-17 15:46 [Bug c/31977] New: can return OK from "int main()" without a return statement by using a goto before the return bmcfadden at cdp dot com
                   ` (2 preceding siblings ...)
  2007-05-17 15:54 ` bmcfadden at cdp dot com
@ 2007-05-17 17:53 ` pinskia at gcc dot gnu dot org
  2007-05-17 19:39 ` bangerth at dealii dot org
  2007-05-17 19:45 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-05-17 17:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2007-05-17 18:53 -------
[pinskia-laptop:~/src] pinskia% gcc -Wreturn-type t.c
t.c: In function 'main':
t.c:15: warning: control reaches end of non-void function


This code is only undefined at runtime which means you cannot error out.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31977


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/31977] can return OK from "int main()" without a return statement by using a goto before the return
  2007-05-17 15:46 [Bug c/31977] New: can return OK from "int main()" without a return statement by using a goto before the return bmcfadden at cdp dot com
                   ` (3 preceding siblings ...)
  2007-05-17 17:53 ` pinskia at gcc dot gnu dot org
@ 2007-05-17 19:39 ` bangerth at dealii dot org
  2007-05-17 19:45 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: bangerth at dealii dot org @ 2007-05-17 19:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from bangerth at dealii dot org  2007-05-17 20:38 -------
Both the C99 standard (section 5.1.2.2.3) and the C++ standard (3.6.1/5)
say that if you hit the end of the main() function, then this is equivalent
to a "return 0;" statement.

W.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31977


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/31977] can return OK from "int main()" without a return statement by using a goto before the return
  2007-05-17 15:46 [Bug c/31977] New: can return OK from "int main()" without a return statement by using a goto before the return bmcfadden at cdp dot com
                   ` (4 preceding siblings ...)
  2007-05-17 19:39 ` bangerth at dealii dot org
@ 2007-05-17 19:45 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-05-17 19:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pinskia at gcc dot gnu dot org  2007-05-17 20:45 -------
(In reply to comment #5)
> Both the C99 standard (section 5.1.2.2.3) and the C++ standard (3.6.1/5)
> say that if you hit the end of the main() function, then this is equivalent
> to a "return 0;" statement.

C90 is different from both of those and it is just undefined behavior there.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31977


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-05-17 19:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-17 15:46 [Bug c/31977] New: can return OK from "int main()" without a return statement by using a goto before the return bmcfadden at cdp dot com
2007-05-17 15:48 ` [Bug c/31977] " bmcfadden at cdp dot com
2007-05-17 15:52 ` bmcfadden at cdp dot com
2007-05-17 15:54 ` bmcfadden at cdp dot com
2007-05-17 17:53 ` pinskia at gcc dot gnu dot org
2007-05-17 19:39 ` bangerth at dealii dot org
2007-05-17 19:45 ` pinskia at gcc dot gnu dot org

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).