[Bug c++/56100] spurious -Wshadow warning with local variable in template class

f.heckenbach@fh-soft.de gcc-bugzilla@gcc.gnu.org
Thu Jan 24 21:25:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56100

--- Comment #2 from Frank Heckenbach <f.heckenbach@fh-soft.de> 2013-01-24 21:25:09 UTC ---
I guess many warnings can only be given correctly during instantiation because
they depend on the actual arguments.

But shadowing is not one of them as the set of identifiers declared doesn't
depend on the arguments. (Even in the case of partial specializations, one
would expect the warning where the specialization is defined, not when it's
instantiated.)

So perhaps a simple fix is to turn off -Wshadow temporarily during
instantiation. After all, the instantiated code has no access to currently
declared global identifiers. This code fails as it should (AFAIK), unless foo
is declared before the template:

template <typename T>
struct bar
{
  int qux () { return foo; }
};

int foo;

int main ()
{
  bar <int> ().qux ();
}



More information about the Gcc-bugs mailing list