[Bug c++/43943] "warning: no return statement in function returning non-void" should be an error

2023-03-31 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43943

Andrew Pinski  changed:

   What|Removed |Added

 CC||contact@thunderperfectwitch
   ||craft.org

--- Comment #9 from Andrew Pinski  ---
*** Bug 109364 has been marked as a duplicate of this bug. ***

[Bug c++/43943] "warning: no return statement in function returning non-void" should be an error

2022-04-19 Thread kdevel at vogtner dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43943

Stefan  changed:

   What|Removed |Added

 CC||kdevel at vogtner dot de

--- Comment #8 from Stefan  ---
(In reply to Jonathan Wakely from comment #4)
> There are cases which are either not diagnosable or cannot be
> written, such as this example from Doug Gregor:
> 
> in generic code, there might not be a way to create a value with the
> appropriate type. For example:
> 
>template
>T maybe_call(std::function f) {
>if (f)
>return f();
>else
>abort_program();
> 
>// Cannot write a return here, because we have no way to
> create a value of type 'T'
>}

One can of course write a return there:

   template
   T maybe_call(std::function f)
   {
  if (f)
 return f();
  else
 abort_program();

  // Cannot write a return here, because we have no way to create a value
of type 'T'
  return f();
   }

which refactors nicely into

   template
   T maybe_call(std::function f)
   {
  if (! f)
 abort_program();
  return f();
   }

[Bug c++/43943] "warning: no return statement in function returning non-void" should be an error

2020-04-26 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43943

Jonathan Wakely  changed:

   What|Removed |Added

 CC||dcb314 at hotmail dot com

--- Comment #7 from Jonathan Wakely  ---
*** Bug 94768 has been marked as a duplicate of this bug. ***

[Bug c++/43943] warning: no return statement in function returning non-void should be an error

2010-04-30 Thread david at rothlis dot net


--- Comment #3 from david at rothlis dot net  2010-04-30 06:05 ---
 a function with a missing return is valid

I just can't reconcile that with the following line from the C++ standard: It
is now invalid to return (explicitly or implicitly) from a function which is
declared to return a value without actually returning a value.  Any insights?

Thanks for the -Werror=return-type tip.


-- 


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



[Bug c++/43943] warning: no return statement in function returning non-void should be an error

2010-04-30 Thread redi at gcc dot gnu dot org


--- Comment #4 from redi at gcc dot gnu dot org  2010-04-30 11:22 ---
(In reply to comment #3)
  a function with a missing return is valid
 
 I just can't reconcile that with the following line from the C++ standard: It
 is now invalid to return (explicitly or implicitly) from a function which is
 declared to return a value without actually returning a value.  Any insights?

Apologies, you're right, in C++ it's not valid and is always undefined
behaviour.

But there have been long discussions on the standard committee reflector about
why it cannot be a diagnostic required error, rather than undefined
behaviour.  There are cases which are either not diagnosable or cannot be
written, such as this example from Doug Gregor:

in generic code, there might not be a way to create a value with the
appropriate type. For example:

   templatetypename T
   T maybe_call(std::functionT(void) f) {
   if (f)
   return f();
   else
   abort_program();

   // Cannot write a return here, because we have no way to create
a value of type 'T'
   }


-- 


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



[Bug c++/43943] warning: no return statement in function returning non-void should be an error

2010-04-30 Thread redi at gcc dot gnu dot org


--- Comment #5 from redi at gcc dot gnu dot org  2010-04-30 11:26 ---
The point being that it's undefined behaviour to /return/ from such a function,
not to /write/ such a function.

If the programmer guarantees the missing return will never happen then
there's no error.

I was wrong to say it's OK as long as the caller doesn't use the return value -
but it is OK as long as control never reaches the missing return


-- 


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



[Bug c++/43943] warning: no return statement in function returning non-void should be an error

2010-04-30 Thread david at rothlis dot net


--- Comment #6 from david at rothlis dot net  2010-04-30 14:01 ---
OK, thanks for the explanation!


-- 


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



[Bug c++/43943] warning: no return statement in function returning non-void should be an error

2010-04-29 Thread pinskia at gcc dot gnu dot org


--- Comment #1 from pinskia at gcc dot gnu dot org  2010-04-29 20:31 ---
-Werror=Wreturn-type will turn just that warning into an error message in
recent GCC's.


-- 


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



[Bug c++/43943] warning: no return statement in function returning non-void should be an error

2010-04-29 Thread redi at gcc dot gnu dot org


--- Comment #2 from redi at gcc dot gnu dot org  2010-04-29 20:36 ---
that should be -Werror=return-type 

but spelling aside, this is not a bug now

the compiler MUST NOT reject it by default, since a function with a missing
return is valid as long as the caller does not use the (missing) return value. 
making this an unconditional error would be non-conforming

if you want that behaviour, use -Werror=return-type


-- 

redi at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||WORKSFORME


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