[Bug c++/101315] New: C++20 lambdas in unevaluated context: erroneously fails with "incomplete type"

janpmoeller at gmx dot de gcc-bugzilla@gcc.gnu.org
Sun Jul 4 13:12:30 GMT 2021


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

            Bug ID: 101315
           Summary: C++20 lambdas in unevaluated context: erroneously
                    fails with "incomplete type"
           Product: gcc
           Version: 11.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janpmoeller at gmx dot de
  Target Milestone: ---

gcc 11.1 and gcc (trunk) fail to compile the following code with --std=c++20:

(1)
////////////////////////////////////////////////////////////////////////////
#include <concepts>
#include <vector>

template <typename Ptr, std::regular_invocable<int> Fn>
struct foo_t {
  foo_t(Ptr ptr) {}
};

template <typename T>
using alias = foo_t<T, decltype([](int) { return 0; })>;

template <typename T>
auto fun(T const& t) {
  return alias<T>{t};
}

int main() {
  std::vector<int> v;
  auto const error = fun(v);
}
////////////////////////////////////////////////////////////////////////////////

Both versions of gcc state:

<source>: In function 'int main()':
<source>:19:14: error: 'const void error' has incomplete type
   19 |   auto const error = fun(v);
      |              ^~~~~
Compiler returned: 1

The issue seems to somehow be related to the alias. Replacing the definition of
fun() with this code results in successful compilation:
(2)
////////////////////////////////////////////////////////////////////////////
template <typename T>
auto fun(T const& t) {
  return foo_t<T, decltype([](int) { return 0; })>{t};
}
////////////////////////////////////////////////////////////////////////////////

Specifying the return type of fun() explicitly results in a different error:
(3)
////////////////////////////////////////////////////////////////////////////
template <typename T>
auto fun(T const& t) -> alias<T> {
  return alias<T>{t};
}
////////////////////////////////////////////////////////////////////////////////
<source>: In function 'int main()':
<source>:19:22: error: 'fun' was not declared in this scope
   19 |   auto const error = fun(v);
      |                      ^~~
Compiler returned: 1

I believe all three variants to be valid c++20.

clang (trunk) compiles versions (1) and (2) of the code, (3) results in a
frontend crash (I'm going to file a bug report against clang for that as well.
I'll comment it here for reference after I'm done).
Also see this link to godbolt: https://godbolt.org/z/r9GMfxzEo


More information about the Gcc-bugs mailing list