Skip to content

"1st argument ('__restrict int') would lose restrict qualifier" when passing (this restrict *)->int to int& argument #82941

@nabijaczleweli

Description

@nabijaczleweli
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 &.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions