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

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |egallager at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
Yup, -Werror=return-type makes gcc reject the reporter's example:

$ /usr/local/bin/g++ -c -Wall -Wextra -pedantic -Werror=return-type 55767.cc
55767.cc: In function ‘int& foo()’:
55767.cc:3:13: error: no return statement in function returning non-void
[-Werror=return-type]
 int& foo() {}
             ^
cc1plus: some warnings being treated as errors
$

(In reply to Jonathan Wakely from comment #1)
> It's not always possible to make it a hard error and refuse to compile the
> code. The function might call a function that never returns (but isn't
> marked with a noreturn attribute) or might be of the form:
> 
>   int& f(bool b) {
>     if (b) {
>       static int i;
>       return i;
>     }
>   }
> 
> If this is never called with a false argument there's no problem. If it's
> never called at all there's no problem.
> 
> Unless GCC's flow analysis is improved I think the most you can hope for is
> enabling -Wreturn-type by default.
> 

There's several bugs with -Wreturn-type I'd like to see fixed before enabling
it by default, for example, bug 55976, bug 68336, and bug 60440

> I use -Werror=return-type, the warning's there already, use it if you want
> it.

Since that works in this case, I'm closing this bug as INVALID.

Reply via email to