Skip to content

[Clang][Regression:21] Rejects valid lambda invocation in constexpr if #156579

@MagentaTreehouse

Description

@MagentaTreehouse

The following C++17 code should be valid:

template <class>
auto f{[] (auto...) {
    if constexpr ([] (auto) { return true; }(0))
        return 0;
}};

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

Error since Clang 21:

<source>:3:19: error: no matching function for call to object of type '(lambda at <source>:3:19)'
    3 |     if constexpr ([] (auto) { return true; }(0))
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:2:21: note: while substituting into a lambda expression here
    2 | auto f{[] (auto...) {
      |                     ^
<source>:8:5: note: in instantiation of variable template specialization 'f' requested here
    8 |     f<int>();
      |     ^
<source>:3:19: note: candidate template ignored: couldn't infer template argument 'auto:1'
    3 |     if constexpr ([] (auto) { return true; }(0))
      |    

See https://compiler-explorer.com/z/Kx5qWPev7.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationlambdaC++11 lambda expressionsregression:21Regression in 21 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions