views:

115

answers:

1

In GCC this code won't compile, because T gets shadowed, however in VS2005 it compiles with no warnings, so what are the assumptions VS compiler is making?

template<typename T>
class Foo
{
    template<typename T>
    void Bar(const T& bar)
    {
      ...
    }
};
+4  A: 

Found the right answer after 3 months of searching :) It's in 14.6.1/4 of the Standard:

A template-parameter shall not be redeclared within its scope (including nested scopes). A template-parameter shall not have the same name as the template name.

Example:

template<class T, int i> class Y {
    int T;
    // error: template-parameter redeclared
    void f() {
        char T;
        // error: template-parameter redeclared
    }
};

template<class X> class X; // error: template-parameter redeclared

If the Microsoft compiler let it compile without errors or even warnings, it is not conforming. I don't know what could drive it to allow it without moaning. You could try to high warning levels.

Johannes Schaub - litb
Thanks, was wondering who was right, but it seems both are
Robert Gould