-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wshadow false positives in function-local classes #33294
Comments
BTW, gcc's -Wshadow diagnostic correctly ignores local variables separated by a local class: https://godbolt.org/g/fp7cmx. |
Sent https://reviews.llvm.org/D35941 for review. |
No diagnostic is ever "needed" in re shadowing; but this code is certainly confusing and I'm glad Clang gives these two diagnostics. I don't think this is a "false" positive at all: the code is confusing because of shadowing, and I'm glad Clang warns about it so that the programmer can go fix their code. Of course if Clang were refusing to compile the code, that would be a bug --- it's definitely legal code; it's just not good code and so it deserves the warnings. |
(cross-posting from https://reviews.llvm.org/D35941) But if I'm overseeing reasons to issue a warning in this case, we could add an analogue of -Wshadow-uncaptured-local for this case. WDYT? |
The fix was committed a while ago: https://reviews.llvm.org/rL309569. |
Merged to 5.0 in r310674. |
Extended Description
https://godbolt.org/g/54XRMT
void f(int a) {
struct A {
void g(int a) {}
A() { int a; }
};
}
3 ::3:16: warning: declaration shadows a local variable [-Wshadow]:1:12: note: previous declaration is here:4:15: warning: declaration shadows a local variable [-Wshadow]:1:12: note: previous declaration is here
void g(int a) {}
^
1 :
void f(int a) {
^
4 :
A() { int a; }
^
1 :
void f(int a) {
^
2 warnings generated.
The local variable
a
of the functionf
can't be accessed from a method of the function-local class A, thus no shadowing occurs and no diagnostic is needed.The text was updated successfully, but these errors were encountered: