Friday, July 6, 2007

Microsoft VC++ 2005 Compiler Bug #2

During a friend class specification the compiler is accepting a typedef name. ISOIEC14882-1998 section 9.1 point 5 states that a "typedef-name that names a class is a class-name, but shall not be used in an elaborated-type-specifier". Sections regarding typedef and friend also defines the same. So this usage must raise a compile time error. Instead the vc++2005 compiler accepts the program and successfully compiles it.

Program 1:

#include "stdafx.h"
#include
using namespace std;

class Alpha;
typedef Alpha Constructor ;

class Beta
{
public:
Beta(){;}
private:
int nVal;
friend class Constructor;
};

class Alpha
{
private:
public:
Alpha() {;}
};

int main()
{
Alpha obj1;
Beta obj2;
return 0;
}

Again if the private data of class Beta is accessed by class data, a compile time error is generated regarding access of private data. Here also error must be usage of typedef name in a place where elaborated-type-specifier must be used. Program 2 given below demonstrates this issue.

Program 2
using namespace std;

class Alpha;
typedef Alpha Constructor ;

class Beta
{
private:
int nVal;
friend class Constructor;
};

class Alpha
{
private:
Beta obj;
public:
Alpha::Alpha()
{
obj.nVal = 10;
cout<<"Constructor\n";
}
};

int main()
{
Alpha obj1;
return 0;
}

Microsoft Comment

Thanks for your feedback. We have tried to reproduce the issue with the latest Visual Studio build (Orcas Beta 1) (http://www.microsoft.com/downloads/details.aspx?FamilyId=36B6609E-6F3D-40F4-8C7D-AD111679D8DC&displaylang=en) and we cannot reproduce it. It is likely a known issue fixed in the latest build. If the issue is critical to you with the release of Visual Studio you are working with, you may contact our Product Support Services (http://support.microsoft.com). Our dedicated Support Engineer will work with you to investigate to issue further.

1 comment:

Mr LK said...

if u remove the "class" keyword before the Constructor , in class Beta , i think i will compile
like "friend Constructor;"

Anyway still bug is there..