[cfe-users] requires clause evaluation within CRTP

Andrey Petrusenko via cfe-users cfe-users at lists.llvm.org
Tue Jun 30 16:02:05 PDT 2020


Hi Everyone,

I've been trying to use libstdc++ <ranges> from GCC 10.1 with Clang 10.0. Even a basic example using `single_view` fails to compile. With some digging, I narrowed it down the following example using CRTP:

```
template <typename D>
struct CRTP {
   void call_foo() requires
     requires (D& v) { v.foo();} {
       static_cast<D*>(this)->foo();
   }
};

struct Test: public CRTP<Test> {
   void foo() { }
};

int main()
{
   Test t;
   t.call_foo();
   return 0;
}
```

```
<source>:16:7: error: invalid reference to function 'call_foo': constraints not satisfied
   t.call_foo();
     ^
<source>:4:27: note: because 'v.foo()' would be invalid: no member named 'foo' in 'Test'
     requires (D& v) { v.foo();} {
                         ^
```

https://godbolt.org/z/jHt2E3

In essence, when Clang checks the requirement it treats the derived class as incomplete, even though an instance was constructed on the previous line.

Thanks,
Andrey


More information about the cfe-users mailing list