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

            Bug ID: 111419
           Summary: Eager instantiation of function return type in concept
                    causes compilation error
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ldionne.2 at gmail dot com
  Target Milestone: ---

The following code fails to compile on GCC:

------------------------------------------------------------
  template <class F>
  auto invoke(F f) -> decltype(f());

  template <class F>
  concept invocable = requires(F&& f) {
    ::invoke(f);
  };

  struct Incomplete;
  template<class T> struct Holder { T t; };

  static_assert(invocable<Holder<Incomplete>& ()>);
------------------------------------------------------------

It produces the following error on GCC:

  <source>: In instantiation of 'struct Holder<Incomplete>':
  <source>:6:11:   required from here
  <source>:10:37: error: 'Holder<T>::t' has incomplete type
    10 | template<class T> struct Holder { T t; };
        |                                     ^
  <source>:9:8: note: forward declaration of 'struct Incomplete'
      9 | struct Incomplete;
        |        ^~~~~~~~~~
  Compiler returned: 1

My understanding is that this should be valid, because nothing actually
requires instantiating the return type of `f()` here, but I'm not sufficiently
well-versed in the details of concepts to know for sure.

Clang and MSVC accept the code.
Godbolt: https://godbolt.org/z/9G5zj47an

Reply via email to