Skip to content

[clang++] unexpected error: substitution into constraint expression resulted in a non-constant expression #93327

@pobrn

Description

@pobrn

Consider the following piece of C++20 code:

template<typename> struct property;

template<typename Derived>
struct B {
    void doit() {
        []<typename R, typename... Args>(R (Derived::*)(Args...)) {
            constexpr bool x = requires {
                requires property<R>::value == 3;
            };
        } (&Derived::f);
    }

};

struct A : B<A> {
    int f();
};

void test() {
    A{}.doit();
}

clang++ emits the following diagnostics:

<source>:8:26: error: substitution into constraint expression resulted in a non-constant expression
    8 |                 requires property<R>::value == 3;
      |                          ^~~~~~~~~~~~~~~~~~~~~~~
<source>:8:26: note: while checking the satisfaction of nested requirement requested here
    8 |                 requires property<R>::value == 3;
      |                          ^~~~~~~~~~~~~~~~~~~~~~~
<source>:8:26: note: in instantiation of requirement here
    8 |                 requires property<R>::value == 3;
      |                          ^~~~~~~~~~~~~~~~~~~~~~~
<source>:8:26: note: while checking the satisfaction of nested requirement requested here
    8 |                 requires property<R>::value == 3;
      |                          ^~~~~~~~~~~~~~~~~~~~~~~
<source>:6:67: note: while substituting into a lambda expression here
    6 |         []<typename R, typename... Args>(R (Derived::*)(Args...)) {
      |                                                                   ^
<source>:20:9: note: in instantiation of member function 'B<A>::doit' requested here
   20 |     A{}.doit();
      |         ^
<source>:8:45: note: non-literal type '<dependent type>' cannot be used in a constant expression
    8 |                 requires property<R>::value == 3;
      |                                             ^

however gcc, msvc, and edg compile it just fine: https://gcc.godbolt.org/z/7rjG4T6o4

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptsconfirmedVerified by a second partyconstexprAnything related to constant evaluationcrash-on-valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions