public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/18588] New: [3.4 4.0 regression] -O2 disables warning "control reaches end of non-void function"
@ 2004-11-21  8:47 debian-gcc at lists dot debian dot org
  2004-11-21  8:47 ` [Bug c/18588] " debian-gcc at lists dot debian dot org
  2004-11-21 14:10 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: debian-gcc at lists dot debian dot org @ 2004-11-21  8:47 UTC (permalink / raw)
  To: gcc-bugs

[forwarded from http://bugs.debian.org/276843]

- gcc-3.4.3 -O2 -Wall foo.c doesn't print the warning
  foo.c: In function `foo':
  foo.c:2: warning: control reaches end of non-void function
  gcc-3.3.4 does.

- gcc-4.0 does print a warning, but the warning in 3.3 was
  more meaningful for the user:
  foo.c: In function 'main':
  foo.c:6: warning: '({anonymous})' is used uninitialized in this function

- for the bar.c example, gcc-3.3 and gcc-3.4 don't print any warning,
  4.0 prints
  foo.c: In function 'main':
  foo.c:6: warning: '({anonymous})' is used uninitialized in this function
  but probaly could do better.


Matthias


Original report follows:

Package: gcc-3.4
Version: 3.4.2-2
Severity: normal


It seems that if a function in a C program is declared "static", the
type of the function is not void, the programmer forgets to add a
"return" statement, and one compiles the program with gcc using -O2,
gcc gives no warning.

Also it seems that -O3 gives a warning only if there is no return
statement at all. It does not properly detect cases where control can
reach end of function.

Sample session follows.

    % cat foo.c          
    static int foo(void)
    {}

    int main(void)
    {
        return foo();
    }
    % cat bar.c
    static int foo(void)
    {
        if (0) {
            return 1;
        }
    }

    int main(void)
    {
        return foo();
    }
    % gcc -Wall foo.c
    foo.c: In function `foo':
    foo.c:2: warning: control reaches end of non-void function
    % gcc -Wall -O1 foo.c
    foo.c: In function `foo':
    foo.c:2: warning: control reaches end of non-void function
    % gcc -Wall -O2 foo.c
    % gcc -Wall -O3 foo.c
    foo.c: In function `foo':
    foo.c:2: warning: no return statement in function returning non-void
    % gcc -Wall bar.c    
    bar.c: In function `foo':
    bar.c:6: warning: control reaches end of non-void function
    % gcc -Wall -O1 bar.c
    bar.c: In function `foo':
    bar.c:6: warning: control reaches end of non-void function
    % gcc -Wall -O2 bar.c
    % gcc -Wall -O3 bar.c
    % gcc --version
    gcc (GCC) 3.4.2 (Debian 3.4.2-2)
    Copyright (C) 2004 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

-- 
           Summary: [3.4 4.0 regression] -O2 disables warning "control
                    reaches end of non-void function"
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: debian-gcc at lists dot debian dot org
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c/18588] [3.4 4.0 regression] -O2 disables warning "control reaches end of non-void function"
  2004-11-21  8:47 [Bug c/18588] New: [3.4 4.0 regression] -O2 disables warning "control reaches end of non-void function" debian-gcc at lists dot debian dot org
@ 2004-11-21  8:47 ` debian-gcc at lists dot debian dot org
  2004-11-21 14:10 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: debian-gcc at lists dot debian dot org @ 2004-11-21  8:47 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic


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


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

* [Bug c/18588] [3.4 4.0 regression] -O2 disables warning "control reaches end of non-void function"
  2004-11-21  8:47 [Bug c/18588] New: [3.4 4.0 regression] -O2 disables warning "control reaches end of non-void function" debian-gcc at lists dot debian dot org
  2004-11-21  8:47 ` [Bug c/18588] " debian-gcc at lists dot debian dot org
@ 2004-11-21 14:10 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-21 14:10 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-11-21 14:10 -------


*** This bug has been marked as a duplicate of 13000 ***

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


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


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

end of thread, other threads:[~2004-11-21 14:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-21  8:47 [Bug c/18588] New: [3.4 4.0 regression] -O2 disables warning "control reaches end of non-void function" debian-gcc at lists dot debian dot org
2004-11-21  8:47 ` [Bug c/18588] " debian-gcc at lists dot debian dot org
2004-11-21 14:10 ` 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).