This patch diagnoses parameter names that shadow the names of inherited fields under -Wshadow-field. It addresses PR34120. Note, unlike GCC, we take into account the accessibility of the field when deciding whether to warn or not.
Details
Details
Diff Detail
Diff Detail
Event Timeline
Comment Actions
Thanks!
lib/Sema/SemaDecl.cpp | ||
---|---|---|
12380–12382 | I think you could move it into the if() above? |
Comment Actions
Updated based on review feedback.
lib/Sema/SemaDecl.cpp | ||
---|---|---|
12380–12382 | You are correct, I'll hoist it. |
Comment Actions
This looks good to me, but you probably want to wait for someone else to review this, too.
Comment Actions
And now i'm having concerns.
struct Base { void* f; }; struct Inherit : Base { static void func(void* f) { // <- does 'f' *actually* shadow the 'f' in the 'Base'? You can't access that non-static member variable from static function. } };
Comment Actions
The diagnostic is correct here, IMO. Consider:
struct Base { int* f; }; struct Inherit : Base { static void func(void* f) { decltype(f) ptr = 0; } };
If the parameter were originally named frobble (so there was no hiding), then the decltype(f) would have resulted in int *. When frobble gets refactored into f, the type of ptr changes to void *.
I think you could move it into the if() above?