"1st argument ('__restrict int') would lose restrict qualifier" when passing (this restrict *)->int to int& argument (original) (raw)
void f(int& x) { (void)x; }
class C { int x; void g() __restrict; };
void C::g() __restrict { f(this->x); }
(same for void f(int const& x)) compiles fine on GCC, but Clang 17 and 19.0.0 (++20240212105217+93cdd1b5cfa3-1~exp1~20240212225341.524) rejects it with
a.cpp:11:5: error: no matching function for call to 'f'
11 | f(this->x);
| ^
a.cpp:1:6: note: candidate function not viable: 1st argument ('__restrict int') would lose restrict qualifier
1 | void f(int& x) {
| ^ ~~~~~~
1 error generated.
I don't think this is valid – this looks like this is of type C restrict *, and thus x is compatible with int restrict &, and it's treating restrict like a cv-qualifier, which I don't think it is (and isn't for pointers), and even if it were I haven't found a position where you could make f take an int restrict &.