Skip to content

Clang behaves different with other compilers for constraint nested lambdas #134193

Open
@zyn0217

Description

@zyn0217

Both were discovered in #133719, but the underlying causes are different from the original issue so I filed a separate one to track these.

  1. The following code causes clang to crash, dating back to Clang 16 and up to trunk:
template <class T>
constexpr auto f{[] (auto arg) {
    return [a{arg}] {
        [] () requires (a == 1) {}();
    };
}};

int main() {
    f<int>(0);
}

https://compiler-explorer.com/z/Tq9xzrPns

  1. Clang accepts the following code, while others don't (discovered by @shafik)
void f() {
    auto f{ 
      [](auto arg) {
        return [a = arg]() 
          requires (a == 1)
         { return a;};
      }
    };

    f(10);
}

https://godbolt.org/z/ncYx8q9f6

This has started since Clang 16.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions