Skip to content

Clang rejects templated consteval lambda within template #144280

Open
@dsacre

Description

@dsacre

Consider this piece of code:

template <int...>
consteval void foo()
{
  constexpr auto bar = []<int...>() consteval {
    return [](int* p) { *p = 42; };
  };
  (void) bar();
}

int main()
{
  foo();
}

This compiles with Clang 18 and earlier, as well as with GCC. Later versions of Clang give this error:

<source>:5:26: error: variable 'p' cannot be implicitly captured in a lambda with no capture-default specified
    5 |     return [](int* p) { *p = 42; };

https://godbolt.org/z/dzqj9Pq9c

Removing consteval from the lambda gets the code to compile, as does converting either foo() or the lambda into a non-template.

I managed to bisect this down to commit 5e767bd.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partyconstevalC++20 constevallambdaC++11 lambda expressionsregression:19Regression in 19 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions