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

Reply via email to