public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/44511]  New: Misdetects missing return with non-void return type, but only if the function is static
@ 2010-06-13  8:55 richard+gcc at sfere dot greenend dot org dot uk
  2010-06-13 10:33 ` [Bug c/44511] " rguenth at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: richard+gcc at sfere dot greenend dot org dot uk @ 2010-06-13  8:55 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2021 bytes --]

GCC 4.5 -Wall warns if your function has a non-void return type but
returns.  It can also detect an infinite loop which means that
"falling off the end" doesn't actually imply a return, and therefore
suppress the warning in that case.

However, if the function is static, this infinite loop detection does
not work:

  richard@deodand:~$ cat t.c
  void *a(void) { for(;;); }
  static void *b(void) { for(;;) { } }
  void foo(void) { b(); }

  richard@deodand:~$ /usr/local/gcc-4.5.0/bin/gcc -c -Wall t.c
  t.c: In function ‘b’:
  t.c:2:1: warning: no return statement in function returning non-void

This real case where I spotted it was a thread function which is
forced to have a return type of 'void *' by the signature of
pthread_create(), but never returns because (by design) the thread
never terminates.

(I assume that the infinite loop detection isn't perfect, but
obviously it shouldn't depend on the linkage of the containing
function.)


richard@deodand:~$ /usr/local/gcc-4.5.0/bin/gcc --version
gcc (GCC) 4.5.0
Copyright (C) 2010 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.

Configured with:

richard@deodand:~$ ../configure -C --prefix=/usr/local/gcc-4.5.0
--enable-languages=c,c++

richard@deodand:~$ uname -a
Linux deodand 2.6.32-5-686-bigmem #1 SMP Tue Jun 1 05:38:08 UTC 2010 i686
GNU/Linux
richard@deodand:~$ dpkg -l libc6
ii  libc6          2.11.1-3       Embedded GNU C Library: Shared libraries


-- 
           Summary: Misdetects missing return with non-void return type, but
                    only if the function is static
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: richard+gcc at sfere dot greenend dot org dot uk


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


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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-44511-4@http.gcc.gnu.org/bugzilla/>
2020-11-22  2:18 ` [Bug c/44511] Misdetects missing return with non-void return type, but only if the function is static eggert at cs dot ucla.edu
2020-11-22 11:38 ` jakub at gcc dot gnu.org
2020-11-22 21:10 ` egallager at gcc dot gnu.org
2010-06-13  8:55 [Bug c/44511] New: " richard+gcc at sfere dot greenend dot org dot uk
2010-06-13 10:33 ` [Bug c/44511] " rguenth at gcc dot gnu dot org
2010-06-13 13:49 ` manu at gcc dot gnu dot org
2010-06-13 14:18 ` rguenth 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).