Re: VC8 template base class member function visibility bug
Situation: A class Test with multiple base classes, one of which is a
template instance BaseTemplate<unsigned>. Then it should be impossible
to access a member function of BaseTemplate<unsigned> from Test by
writing:
BaseTemplate::test(123);
Indeed, VC7.1 and Intel 9.1 compiler complain that the template
parameter for BaseTemplate is missing. VC8 compiles this anyhow and
the result is terribly wrong. The function call jumps into no man's
land and modifies some of the other base classes' data.
That was my weekend.
I think this is legal as C++ spec says:
14.6.1 Locally declared names [temp.local]
1 Like normal (non-template) classes, class templates have an
injected-class-name (clause 9). The injected-class-name can
be used with or without a template-argument-list. When it is used without a
template-argument-list, it is equivalent to
the injected-class-name followed by the template-parameters of the class
template enclosed in <>. When it is used with
a template-argument-list, it refers to the specified class template
specialization, which could be the current specialization
or another specialization.
#include <iostream>
using namespace std;
template
<typename T>
class BaseTemplate
{
T t;
public:
BaseTemplate(): t(0)
{
}
protected:
void test(unsigned i)
{
t+=i;
}
};
struct A
{
unsigned a;
A():a(0){}
};
struct B
{
unsigned b;
B():b(0){}
};
class Test:
public A,
public BaseTemplate<unsigned>,
public B
{
public:
void showProb()
{
BaseTemplate<unsigned>::test(123); //ok
cout<<b<<endl;
BaseTemplate::test(123); //should not compile
cout<<b<<endl; //ouch
}
};
int main()
{
Test test;
test.showProb();
}
--
Vladimir Nesterovsky