public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kdevel at vogtner dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/43943] "warning: no return statement in function returning non-void" should be an error
Date: Tue, 19 Apr 2022 09:55:16 +0000	[thread overview]
Message-ID: <bug-43943-4-W2ywAyY9Ay@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-43943-4@http.gcc.gnu.org/bugzilla/>

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();
   }

  parent reply	other threads:[~2022-04-19  9:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-43943-4-W2ywAyY9Ay@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).