public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/43943] "warning: no return statement in function returning non-void" should be an error
[not found] <bug-43943-4@http.gcc.gnu.org/bugzilla/>
@ 2020-04-26 9:44 ` redi at gcc dot gnu.org
2022-04-19 9:55 ` kdevel at vogtner dot de
2023-03-31 18:38 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-26 9:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43943
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dcb314 at hotmail dot com
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 94768 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43943] "warning: no return statement in function returning non-void" should be an error
[not found] <bug-43943-4@http.gcc.gnu.org/bugzilla/>
2020-04-26 9:44 ` [Bug c++/43943] "warning: no return statement in function returning non-void" should be an error redi at gcc dot gnu.org
@ 2022-04-19 9:55 ` kdevel at vogtner dot de
2023-03-31 18:38 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 9+ messages in thread
From: kdevel at vogtner dot de @ 2022-04-19 9:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43943
Stefan <kdevel at vogtner dot de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kdevel at vogtner dot de
--- Comment #8 from Stefan <kdevel at vogtner dot de> ---
(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<typename T>
> T maybe_call(std::function<T(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'
> }
One can of course write a return there:
template<typename T>
T maybe_call(std::function<T(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'
return f();
}
which refactors nicely into
template<typename T>
T maybe_call(std::function<T(void)> f)
{
if (! f)
abort_program();
return f();
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43943] "warning: no return statement in function returning non-void" should be an error
[not found] <bug-43943-4@http.gcc.gnu.org/bugzilla/>
2020-04-26 9:44 ` [Bug c++/43943] "warning: no return statement in function returning non-void" should be an error redi at gcc dot gnu.org
2022-04-19 9:55 ` kdevel at vogtner dot de
@ 2023-03-31 18:38 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-31 18:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43943
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |contact@thunderperfectwitch
| |craft.org
--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 109364 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43943] "warning: no return statement in function returning non-void" should be an error
2010-04-29 20:13 [Bug c++/43943] New: " david at rothlis dot net
` (4 preceding siblings ...)
2010-04-30 11:26 ` redi at gcc dot gnu dot org
@ 2010-04-30 14:01 ` david at rothlis dot net
5 siblings, 0 replies; 9+ messages in thread
From: david at rothlis dot net @ 2010-04-30 14:01 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43943] "warning: no return statement in function returning non-void" should be an error
2010-04-29 20:13 [Bug c++/43943] New: " david at rothlis dot net
` (3 preceding siblings ...)
2010-04-30 11:22 ` redi at gcc dot gnu dot org
@ 2010-04-30 11:26 ` redi at gcc dot gnu dot org
2010-04-30 14:01 ` david at rothlis dot net
5 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-04-30 11:26 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43943] "warning: no return statement in function returning non-void" should be an error
2010-04-29 20:13 [Bug c++/43943] New: " david at rothlis dot net
` (2 preceding siblings ...)
2010-04-30 6:05 ` david at rothlis dot net
@ 2010-04-30 11:22 ` redi at gcc dot gnu dot org
2010-04-30 11:26 ` redi at gcc dot gnu dot org
2010-04-30 14:01 ` david at rothlis dot net
5 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-04-30 11:22 UTC (permalink / raw)
To: gcc-bugs
------- 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:
template<typename T>
T maybe_call(std::function<T(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
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43943] "warning: no return statement in function returning non-void" should be an error
2010-04-29 20:13 [Bug c++/43943] New: " david at rothlis dot net
2010-04-29 20:32 ` [Bug c++/43943] " pinskia at gcc dot gnu dot org
2010-04-29 20:36 ` redi at gcc dot gnu dot org
@ 2010-04-30 6:05 ` david at rothlis dot net
2010-04-30 11:22 ` redi at gcc dot gnu dot org
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: david at rothlis dot net @ 2010-04-30 6:05 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43943] "warning: no return statement in function returning non-void" should be an error
2010-04-29 20:13 [Bug c++/43943] New: " david at rothlis dot net
2010-04-29 20:32 ` [Bug c++/43943] " pinskia at gcc dot gnu dot org
@ 2010-04-29 20:36 ` redi at gcc dot gnu dot org
2010-04-30 6:05 ` david at rothlis dot net
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-04-29 20:36 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43943] "warning: no return statement in function returning non-void" should be an error
2010-04-29 20:13 [Bug c++/43943] New: " david at rothlis dot net
@ 2010-04-29 20:32 ` pinskia at gcc dot gnu dot org
2010-04-29 20:36 ` redi at gcc dot gnu dot org
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-04-29 20:32 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-03-31 18:38 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-43943-4@http.gcc.gnu.org/bugzilla/>
2020-04-26 9:44 ` [Bug c++/43943] "warning: no return statement in function returning non-void" should be an error redi at gcc dot gnu.org
2022-04-19 9:55 ` kdevel at vogtner dot de
2023-03-31 18:38 ` pinskia at gcc dot gnu.org
2010-04-29 20:13 [Bug c++/43943] New: " david at rothlis dot net
2010-04-29 20:32 ` [Bug c++/43943] " pinskia at gcc dot gnu dot org
2010-04-29 20:36 ` redi at gcc dot gnu dot org
2010-04-30 6:05 ` david at rothlis dot net
2010-04-30 11:22 ` redi at gcc dot gnu dot org
2010-04-30 11:26 ` redi at gcc dot gnu dot org
2010-04-30 14:01 ` david at rothlis dot net
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).