Skip to content

[Clang] Wrong constraint evaluation for lambda in unevaluated context #124497

Open
@MagentaTreehouse

Description

@MagentaTreehouse

The following should be valid C++20 code:

template <class T>
using F = decltype([] (auto a) requires (sizeof(T) > sizeof a) {});

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

Clang rejects with:

<source>:6:5: error: no matching function for call to object of type 'F<int>' (aka '(lambda at <source>:2:20)')
    6 |     f(char{});
      |     ^
<source>:2:20: note: candidate template ignored: constraints not satisfied [with a:auto = char]
    2 | using F = decltype([] (auto a) requires (sizeof(T) > sizeof a) {});
      |                    ^
<source>:2:42: note: because 'sizeof(char) > sizeof a' (1 > 1) evaluated to false
    2 | using F = decltype([] (auto a) requires (sizeof(T) > sizeof a) {});
      |                                          ^

Somehow it got char substituted into T in sizeof(T)?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptslambdaC++11 lambda expressionsregression:16Regression in 16 release

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions