Skip to content

[clang] Failed to compile simple and legal code while gcc is ok #141732

Open
@yaoxinliu

Description

@yaoxinliu

See: https://godbolt.org/z/GqbzYfa78
Related Issue: #141693

template<typename T>
concept IsOK =
    []<typename U> consteval -> bool { return requires { requires sizeof(U) > 1; }; }.template operator()<T>();

static_assert(IsOK<int>);

int main() {
}

gcc is ok, but clang gives errors as follows:

<source>:3:67: error: substitution into constraint expression resulted in a non-constant expression
    3 |     []<typename U> consteval -> bool { return requires { requires sizeof(U) > 1; }; }.template operator()<T>();
      |                                                                   ^~~~~~~~~~~~~
<source>:3:67: note: while checking the satisfaction of nested requirement requested here
    3 |     []<typename U> consteval -> bool { return requires { requires sizeof(U) > 1; }; }.template operator()<T>();
      |                                                                   ^~~~~~~~~~~~~
<source>:3:67: note: in instantiation of requirement here
    3 |     []<typename U> consteval -> bool { return requires { requires sizeof(U) > 1; }; }.template operator()<T>();
      |                                                                   ^~~~~~~~~~~~~
<source>:3:67: note: while checking the satisfaction of nested requirement requested here
    3 |     []<typename U> consteval -> bool { return requires { requires sizeof(U) > 1; }; }.template operator()<T>();
      |                                                                   ^~~~~~~~~~~~~
<source>:3:38: note: while substituting into a lambda expression here
    3 |     []<typename U> consteval -> bool { return requires { requires sizeof(U) > 1; }; }.template operator()<T>();
      |                                      ^
<source>:3:5: note: while substituting template arguments into constraint expression here
    3 |     []<typename U> consteval -> bool { return requires { requires sizeof(U) > 1; }; }.template operator()<T>();
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:5:15: note: while checking the satisfaction of concept 'IsOK<int>' requested here
    5 | static_assert(IsOK<int>);
      |               ^~~~~~~~~
<source>:3:67: note: subexpression not valid in a constant expression
    3 |     []<typename U> consteval -> bool { return requires { requires sizeof(U) > 1; }; }.template operator()<T>();
      |                                                                   ^
<source>:5:15: error: static assertion failed
    5 | static_assert(IsOK<int>);
      |               ^~~~~~~~~
<source>:5:15: note: because 'int' does not satisfy 'IsOK'
<source>:3:5: note: because '[]<typename U>() -> bool {
    return requires { requires <<error-expression>>; };
}.template operator()<int>()' evaluated to false
    3 |     []<typename U> consteval -> bool { return requires { requires sizeof(U) > 1; }; }.template operator()<T>();
      |     ^
2 errors generated.
Compiler returned: 1

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptsdiverges-from:gccDoes the clang frontend diverge from gcc on this issuelambdaC++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