public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/8609: Superfluous warning when -std=c99/gnu99 and noreturn on main()
@ 2002-11-22  9:46 Matthias Klose
  0 siblings, 0 replies; 5+ messages in thread
From: Matthias Klose @ 2002-11-22  9:46 UTC (permalink / raw)
  To: gcc-gnats, debian-gcc


>Number:         8609
>Category:       c
>Synopsis:       Superfluous warning when -std=c99/gnu99 and noreturn on main()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Nov 16 05:06:03 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Agthorr <agthorr@barsoom.org>
>Release:        3.2.1 (Debian) (Debian unstable)
>Organization:
The Debian Project
>Environment:
System: Debian GNU/Linux (unstable)
Architecture: i686
Configured with: /home/packages/gcc/3.2/gcc-3.2-3.2.1ds5/src/configure -v --enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-java-gc=boehm --enable-objc-gc i386-linux
>Description:
[ Reported to the Debian BTS as report #141015.
  Please CC 141015@bugs.debian.org on replies.
  Log of report can be found at http://bugs.debian.org/141015 ]

[ rechecked with gcc-3.2.1 prerelease ]

The following program generates a superfluous warning when compiled
with -std=c99 or -std=gnu99.

------------------------------------------------------------------------
#include <stdlib.h>
int main (void) __attribute__ ((noreturn));
int main (void)
{
        exit(1);
}
------------------------------------------------------------------------
volition:~/tmp$ gcc-3.0 -std=c99  -c test.c
test.c: In function `main':
test.c:6: warning: function declared `noreturn' has a `return' statement
volition:~/tmp$
------------------------------------------------------------------------

Obviously, this warning is bogus since there is no return statement
anywhere in the program :>  The warning is not produced by gcc 2.95.4
nor in the default -std=gnu89 mode.

Although this example is trivial, I encountered the bug in an actual
program that depends on -std=gnu99 (since C99 features are used).  In
the program, main() starts an event loop which never directly returns;
the program exits by calling exit().
	
>How-To-Repeat:
	
>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:


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

* Re: c/8609: Superfluous warning when -std=c99/gnu99 and noreturn on main()
@ 2002-11-25  7:16 bangerth
  0 siblings, 0 replies; 5+ messages in thread
From: bangerth @ 2002-11-25  7:16 UTC (permalink / raw)
  To: 141015, agthorr, gcc-bugs, gcc-prs, nobody

Synopsis: Superfluous warning when -std=c99/gnu99 and noreturn on main()

State-Changed-From-To: analyzed->closed
State-Changed-By: bangerth
State-Changed-When: Mon Nov 18 17:13:39 2002
State-Changed-Why:
    Closed based on these comments:
    
    Date: Mon, 18 Nov 2002 16:30:10 -0800
    From: Agthorr <agthorr@barsoom.org>
    To: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
    Subject: Re: c/8609: Superfluous warning when -std=c99/gnu99 and noreturn on main()
    
    I was mistaken.  gcc 2.95 complains when main() is not noreturn, which
    caused me to declare main() as noreturn.  Later, I upgraded to gcc
    3.0, which complains when main() is noreturn.
    
    The warning described in the original bug still seems wrong to me, but
    it's much less bothersome.  I'll admit to being a perfectionist though ;)
    
    
    Date: Mon, 18 Nov 2002 17:10:48 -0800
    From: Agthorr <agthorr@barsoom.org>
    To: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
    Subject: Re: c/8609: Superfluous warning when -std=c99/gnu99 and noreturn on main()
    
    On Mon, Nov 18, 2002 at 06:46:42PM -0600, Wolfgang Bangerth wrote:
    > So am I right that you now have two switches for both compilers that give
    > you a warning on one but not the other, and omitting the right one on the
    > right compiler makes the warning go away?
    
    Yes.
    
    > If this is the case, I would suggest we close the report. I think, this is
    > such a corner case (main() being the only function for which an implicit
    > return is mandated), that it is hardly worth to think about it more if
    > there is a workaround.
    
    Fine by me.
    

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8609


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

* Re: c/8609: Superfluous warning when -std=c99/gnu99 and noreturn on main()
@ 2002-11-25  0:46 Wolfgang Bangerth
  0 siblings, 0 replies; 5+ messages in thread
From: Wolfgang Bangerth @ 2002-11-25  0:46 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c/8609; it has been noted by GNATS.

From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: Agthorr <agthorr@barsoom.org>
Cc: bangerth@dealii.org, <141015@bugs.debian.org>, <gcc-bugs@gcc.gnu.org>,
   <gcc-prs@gcc.gnu.org>, <nobody@gcc.gnu.org>, <gcc-gnats@gcc.gnu.org>
Subject: Re: c/8609: Superfluous warning when -std=c99/gnu99 and noreturn on
 main()
Date: Mon, 18 Nov 2002 18:04:56 -0600 (CST)

 On Mon, 18 Nov 2002, Agthorr wrote:
 
 > Well, I also compile with -Wmissing-noreturn.  If I add the noreturn
 > attribute to main, gcc complains that the function returns.  If I
 > remove the noreturn, gcc complains that the function does not return.
 > 
 > gcc can't have it both ways. ;)
 
 However, if I remove the noreturn attribute line, I cannot make gcc 
 complain about the code:
 tmp/g> cat x.c
 #include <stdlib.h>
 
 int main (void)
 {
         exit(1);
 }
 tmp/g> /home/bangerth/bin/gcc-3.3x-pre/bin/gcc -Wmissing-noreturn -std=gnu99 -c x.c
 tmp/g>
 
 What do you do differently?
 
 Regards
   Wolfgang
 
 -------------------------------------------------------------------------
 Wolfgang Bangerth              email:           bangerth@ticam.utexas.edu
                                www: http://www.ticam.utexas.edu/~bangerth
 
 


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

* Re: c/8609: Superfluous warning when -std=c99/gnu99 and noreturn on main()
@ 2002-11-24 17:24 Agthorr
  0 siblings, 0 replies; 5+ messages in thread
From: Agthorr @ 2002-11-24 17:24 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c/8609; it has been noted by GNATS.

From: Agthorr <agthorr@barsoom.org>
To: bangerth@dealii.org, 141015@bugs.debian.org, gcc-bugs@gcc.gnu.org,
	gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@Gcc.gnu.org
Cc:  
Subject: Re: c/8609: Superfluous warning when -std=c99/gnu99 and noreturn on main()
Date: Mon, 18 Nov 2002 15:47:24 -0800

 Well, I also compile with -Wmissing-noreturn.  If I add the noreturn
 attribute to main, gcc complains that the function returns.  If I
 remove the noreturn, gcc complains that the function does not return.
 
 gcc can't have it both ways. ;)
 
 On Mon, Nov 18, 2002 at 10:55:07PM -0000, bangerth@dealii.org wrote:
 > Synopsis: Superfluous warning when -std=c99/gnu99 and noreturn on main()
 > 
 > State-Changed-From-To: open->analyzed
 > State-Changed-By: bangerth
 > State-Changed-When: Mon Nov 18 14:55:06 2002
 > State-Changed-Why:
 >     I can reproduce this. I think, the warning comes from the fact
 >     that in C99, main() has an implicit "return 0" at its end,
 >     indicating that if you fall off the end of main(), the
 >     programs return value is zero. This also explains why it
 >     only happens with main(), not if you rename the function.
 >     
 >     That being said, since you cannot control who calls main
 >     and how, what reason should you have to mark main() as
 >     noreturn? It should not make any difference, so why do
 >     it? I have difficulty seeing this as a bug...
 > 
 > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8609
 > 


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

* Re: c/8609: Superfluous warning when -std=c99/gnu99 and noreturn on main()
@ 2002-11-24 13:30 bangerth
  0 siblings, 0 replies; 5+ messages in thread
From: bangerth @ 2002-11-24 13:30 UTC (permalink / raw)
  To: 141015, agthorr, gcc-bugs, gcc-prs, nobody

Synopsis: Superfluous warning when -std=c99/gnu99 and noreturn on main()

State-Changed-From-To: open->analyzed
State-Changed-By: bangerth
State-Changed-When: Mon Nov 18 14:55:06 2002
State-Changed-Why:
    I can reproduce this. I think, the warning comes from the fact
    that in C99, main() has an implicit "return 0" at its end,
    indicating that if you fall off the end of main(), the
    programs return value is zero. This also explains why it
    only happens with main(), not if you rename the function.
    
    That being said, since you cannot control who calls main
    and how, what reason should you have to mark main() as
    noreturn? It should not make any difference, so why do
    it? I have difficulty seeing this as a bug...

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8609


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

end of thread, other threads:[~2002-11-19  1:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-22  9:46 c/8609: Superfluous warning when -std=c99/gnu99 and noreturn on main() Matthias Klose
2002-11-24 13:30 bangerth
2002-11-24 17:24 Agthorr
2002-11-25  0:46 Wolfgang Bangerth
2002-11-25  7:16 bangerth

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