[clang][Sema] Invalid -Wshadow diagnostics in friend functions defined inside the class
Clang raises a -Wshadow warning for the function parameter x in this C++ friend function:
class Foo {
int x;
friend bool operator==(const Foo& f, int x) {
return f.x == x;
}
};
Godbolt link: https://godbolt.org/z/dnr1sEaWM
Practically, I would argue there is no shadowing: the field x is not accessible inside the friend function (if you try to access it, you get "error: invalid use of non-static data member"). Gcc also does not give a warning for this case.
@llvm/issue-subscribers-clang-frontend
Author: Bruno De Fraine (brunodf-gf)
class Foo {
int x;
friend bool operator==(const Foo& f, int x) {
return f.x == x;
}
};
Godbolt link: https://godbolt.org/z/dnr1sEaWM
Practically, I would argue there is no shadowing: the field x is not accessible inside the friend function (if you try to access it, you get "error: invalid use of non-static data member"). Gcc also does not give a warning for this case.
Hi @brunodf-gf, I read the issue and did some research and I think I found a good starting point to work on it. Working on the PR rn.
Created a PR fixing the issue. #221249