Friday, July 6, 2007

Microsoft VC++ 2005 Compiler Bug #1

It seems like there is implementation difference from ISOIEC14882-1998 rules regarding multiple inheritance and private access specifier.
The private virtual base destructor is accessible from most derived class. No compile time error and no runtime error for program.

class DisableDerive
{
public:
DisableDerive(){ ; }

private:
~DisableDerive(){ ; }
friend class NonDerivable;
};

class NonDerivable: virtual protected DisableDerive
{
private:
int m_nVal;
public:
NonDerivable()
{
std::cout<<"NonDerivable::NonDerivable()\n";
m_nVal = -1;
}
~NonDerivable()
{
std::cout<<"NonDerivable::~NonDerivable()\n";
}
void SetValue( int nVal ){ m_nVal = 10; }
};

class TryDerive: public NonDerivable
{
public:
TryDerive(){ ; }
~TryDerive(){ ; }
};

int main()
{
TryDerive a;
return 0;
}


This code is getting compiled and executed. But there must be an error because the DisableDerive::~DisableDerive must not be accessible from TryDerive. The constructor is not accessible and the problem is only with destructor.

This code is giving expected compile time error in Visual Studio 6.0.

Microsoft Comments on this bug

Thanks for your feedback. We have reproduced this bug on Win2003 SP2 and OrcasBeta1VSTS, and we are sending this bug to the appropriate group within the Visual Studio Product Team for triage and resolution. Thank you, Visual Studio Product Team.
Posted by Microsoft on 6/26/2007 at 8:24 PM