Skip to content

Crash when passing a lambda to function in decltype, or no viable conversion from lambda to itself #111283

@HolyBlackCat

Description

@HolyBlackCat

The following code sometimes segfaults the compiler, and sometimes gives a nonsensical error.

v1:

void foo(auto &&) {}
auto bar(auto &&a) -> decltype (foo([]( auto && ... ){})) {}
struct A {};

int main()
{
    bar(A());
}

v2:

namespace N
{
    void foo(auto &&) {}
    auto bar(auto &&a) -> decltype (foo([]( auto && ... ){})) {}
    struct A {};
}

int main()
{
    bar(N::A());
}

Here's v1 segfaulting Clang 19: https://gcc.godbolt.org/z/1Ycq96r6b

And v2 emits this error:

<source>:10:5: error: no matching function for call to 'bar'
   10 |     bar(N::A());
      |     ^~~
<source>:4:10: note: candidate template ignored: substitution failure [with a:auto = N::A]: no viable conversion from '(lambda at <source>:4:41)' to 'N::(lambda at <source>:4:41)'
    4 |     auto bar(auto &&a) -> decltype (foo([]( auto && ... ){})) {}
      |          ^  

There's some variance here. My local Clang 19 (as opposed to godbolt) segfaults on v2 instead, and emits this error on v1.

Clang 18 and trunk on godbolt emits this error instead of segfaulting on both v1 and v2.

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partycrashPrefer [crash-on-valid] or [crash-on-invalid]lambdaC++11 lambda expressions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions