public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54278] New: "control reaches end of non-void function
@ 2012-08-16  0:00 travis at gockelhut dot com
  2012-08-16  0:07 ` [Bug c++/54278] __attribute__((noreturn)) called from destructor when another auto-scoped variable has a non-trivial dtor erroneously fails with "control reaches end of non-void function" at -O0 travis at gockelhut dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: travis at gockelhut dot com @ 2012-08-16  0:00 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54278
           Summary: "control reaches end of non-void function
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: travis@gockelhut.com


Created attachment 28027
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28027
compile with g++-4.7 -Wreturn-type to recreate

struct ThingWithDtor
    {
        ~ThingWithDtor();
    };

    struct Aborter
    {
        __attribute__((noreturn)) ~Aborter();
    };

    int foo(int x)
    {
        ThingWithDtor t __attribute__((unused));
        if (x)
            return x;
        Aborter();
    }


noreturn.cpp: In function ‘int foo(int)’:
noreturn.cpp:16:1: warning: control reaches end of non-void function
[-Wreturn-type]


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

* [Bug c++/54278] __attribute__((noreturn)) called from destructor when another auto-scoped variable has a non-trivial dtor erroneously fails with "control reaches end of non-void function" at -O0
  2012-08-16  0:00 [Bug c++/54278] New: "control reaches end of non-void function travis at gockelhut dot com
@ 2012-08-16  0:07 ` travis at gockelhut dot com
  2013-08-21 10:19 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: travis at gockelhut dot com @ 2012-08-16  0:07 UTC (permalink / raw)
  To: gcc-bugs

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

Travis Gockel <travis at gockelhut dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unknown                     |4.7.0
            Summary|"control reaches end of     |__attribute__((noreturn))
                   |non-void function           |called from destructor when
                   |                            |another auto-scoped
                   |                            |variable has a non-trivial
                   |                            |dtor erroneously fails with
                   |                            |"control reaches end of
                   |                            |non-void function" at -O0

--- Comment #1 from Travis Gockel <travis at gockelhut dot com> 2012-08-16 00:06:48 UTC ---
Accidentally hit enter...

The key here is that ThingWithDtor is non-trivial -- if you mark
~ThingWithDtor() as =default (or remove the declaration), it will not warn. If
you call a noreturn function directly instead of relying on ~Aborter(), it will
not warn. If both branches of the if create an Aborter, it will not warn.


Everything must be compiled with -Wreturn-type and -O0. This all compiles just
fine with g++ 4.6.3.

---

Using built-in specs.
COLLECT_GCC=g++-4.7
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.7.0-7ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs
--enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.7 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7
--libdir=/usr/lib --enable-nls --disable-bootstrap --with-sysroot=/
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror
--with-arch-32=i686 --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.0 (Ubuntu/Linaro 4.7.0-7ubuntu3)


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

* [Bug c++/54278] __attribute__((noreturn)) called from destructor when another auto-scoped variable has a non-trivial dtor erroneously fails with "control reaches end of non-void function" at -O0
  2012-08-16  0:00 [Bug c++/54278] New: "control reaches end of non-void function travis at gockelhut dot com
  2012-08-16  0:07 ` [Bug c++/54278] __attribute__((noreturn)) called from destructor when another auto-scoped variable has a non-trivial dtor erroneously fails with "control reaches end of non-void function" at -O0 travis at gockelhut dot com
@ 2013-08-21 10:19 ` paolo.carlini at oracle dot com
  2020-11-21 19:53 ` [Bug c++/54278] [6 regression] " danikiw542 at bcpfm dot com
  2020-11-21 22:58 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-21 10:19 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-08-21
                 CC|travis at gockelhut dot com        |
     Ever confirmed|0                           |1


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

* [Bug c++/54278] [6 regression] __attribute__((noreturn)) called from destructor when another auto-scoped variable has a non-trivial dtor erroneously fails with "control reaches end of non-void function" at -O0
  2012-08-16  0:00 [Bug c++/54278] New: "control reaches end of non-void function travis at gockelhut dot com
  2012-08-16  0:07 ` [Bug c++/54278] __attribute__((noreturn)) called from destructor when another auto-scoped variable has a non-trivial dtor erroneously fails with "control reaches end of non-void function" at -O0 travis at gockelhut dot com
  2013-08-21 10:19 ` paolo.carlini at oracle dot com
@ 2020-11-21 19:53 ` danikiw542 at bcpfm dot com
  2020-11-21 22:58 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: danikiw542 at bcpfm dot com @ 2020-11-21 19:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54278

danikiw542 at bcpfm dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |danikiw542 at bcpfm dot com

--- Comment #8 from danikiw542 at bcpfm dot com ---
This warning is as the admonition portrayed In kind with no value. If control
arrives at the end of a function and no return is encountered, GCC accepts an
arrival with no arrival value. However, for this, the capacity requires an
arrival value. Toward the finish of the function, return suitable value,
regardless of whether control never comes there.

Also you can solve that by doing follows:
The problem is that other compilers have a warning about "unreachable code". If
every switch case is handled, the compiler detects that the return statement
cannot be reached. I have to suppress this warning or use the preprocessor to
only have that return statement on certain compilers. Something like this piece
of code.   Link to the code.

https://kodlogs.com/blog/852/warning-control-reaches-end-non-void-function-wreturn-type

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

* [Bug c++/54278] [6 regression] __attribute__((noreturn)) called from destructor when another auto-scoped variable has a non-trivial dtor erroneously fails with "control reaches end of non-void function" at -O0
  2012-08-16  0:00 [Bug c++/54278] New: "control reaches end of non-void function travis at gockelhut dot com
                   ` (2 preceding siblings ...)
  2020-11-21 19:53 ` [Bug c++/54278] [6 regression] " danikiw542 at bcpfm dot com
@ 2020-11-21 22:58 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-11-21 22:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54278

--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to danikiw542 from comment #8)
> https://kodlogs.com/blog/852/warning-control-reaches-end-non-void-function-
> wreturn-type


values not defined in enum's are still valid and well defined, that is a
different issue all together and unrelated to this bug.  There are others which
have been closed as invalid for the reason mentioned here.

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-16  0:00 [Bug c++/54278] New: "control reaches end of non-void function travis at gockelhut dot com
2012-08-16  0:07 ` [Bug c++/54278] __attribute__((noreturn)) called from destructor when another auto-scoped variable has a non-trivial dtor erroneously fails with "control reaches end of non-void function" at -O0 travis at gockelhut dot com
2013-08-21 10:19 ` paolo.carlini at oracle dot com
2020-11-21 19:53 ` [Bug c++/54278] [6 regression] " danikiw542 at bcpfm dot com
2020-11-21 22:58 ` pinskia at gcc dot gnu.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).