False positive in diagnostic shadow-field
| Bugzilla Link | 48477 |
| Version | unspecified |
| OS | All |
| CC | @zygoloid |
Extended Description
struct Base { int type; };
struct S : public Base {
static int Test(int type) {
return type;
}
};
results in a warning on method Test. Since that method is static, there's no shadowing.
Technically there still is shadowing here:
struct S : public Base {
static int Test() {
int k = sizeof(type); // ok, size of Base::type
decltype(type) k2; // ok, type of Base::type
}
};
... but maybe it makes sense to suppress the warning, or move it to a more-specific warning group, if the shadowed member couldn't actually be named in an evaluated context.
Presumably a similar concern would apply if the shadowed member were an inaccessible member of the base class:
class Base { int type; }; struct Derived : public Base { int foo(int type) {} // should we suppress the shadow-field warning here? };
... since similarly, in "ordinary" circumstances, there can only be a shadowing bug (that is, an intent to use the base class field that actually names something else) if the programmer makes two errors at once (incorrectly thinking the field is usable, and not noticing that it's shadowed).