Microsoft Visual C++ 2008 SP1 Incorrect enumerator scoping

Back to programming

This bug is only present when language extensions are enabled. Because the base class of B (A<N>) is dependent on a template parameter, it's contents should not be visible to B's definition. However, now the compiler thinks that the N in 'typedef A<N> Base;' refers to the N in the base class (which is private) rather than the template parameter N. Microsoft replied with the following:

"Hi: this is bacause [sic] with 'language extensions' enabled (or to put it another way - strict mode disabled) the compiler looks into dependent base-classes and hence finds the enumerator N. It is unlikely that we'll fix this anytime soon as too much existing code would break. Even the EDG compiler in non-strict mode look [sic] into dependent base-classes."

template <int N>
class A
{
private:
    enum
    {
        N = 1
    };
};

template <int N>
class B
    : public A<N>
{
public:
    typedef A<N> Base;
};

int main()
{
    B<1> a;
    return 0;
}