VC 7.1 Bug related to templates ?!

M

MatthiasBiel

Hi all,

Microsoft Visual C++ .NET 69586-112-0293626-18840
doesn't compile the code below, it issues a C2146.

template<class T>
class A {
public:
typedef T X;
};

A<A<int> >::X::X i;

Is a fix available for this problem ?

Thank you,

Matthias
 
D

David Lowndes

Microsoft Visual C++ .NET 69586-112-0293626-18840
doesn't compile the code below, it issues a C2146.

template<class T>
class A {
public:
typedef T X;
};

A<A<int> >::X::X i;

Is a fix available for this problem ?

Matthias,

The B1 VS2005 compiler also doesn't like it either, though the Comeau
online compiler thinks it's fine.

I suggest that you submit a bug report on it at
http://labs.msdn.microsoft.com/productfeedback/

The VS2005 B1 compiler produces the following errors:

error C2146: syntax error : missing ';' before identifier 'i'
error C2350: 'A<T>::{ctor}' is not a static member
with
[
T=int
]
fatal error C1903: unable to recover from previous error(s); stopping
compilation


Dave
 
M

MatthiasBiel

Dave,

thank you for your help!

I found another problematic case:

template<class T>
class A {
public:
typedef T X;
};

class B {
public:
void Test(int);
};

class C {
public:
template<class InstantA>
void Test(const InstantA& a, void (InstantA::X::*x)(int)) const;
};

void Test() {
C().Test(A<B>(), &B::Test);
}

In this case the VC7.1 complains about the declaration of C::Test.
It can not resolve X and issues:

error C2653: 'X' : is not a class or namespace name

It compiles fine with GCC 3.3.1 and the Comeau online compiler.

At least there is a simple workaround for this problem, VC works fine
too, if C is defined in this way:

class C {
public:
template<class InstantA, class X>
void Test(const InstantA& a, void (X::*x)(int)) const;
};

I'll submit a bug report for both cases.

Matthias
 
D

David Lowndes

I'll submit a bug report for both cases.

Can you post the link to your report back here and I'll add a vote to
it since I can repro it.

Cheers
Dave
 
V

Vladimir Nesterovsky

template said:
class A {
public:
typedef T X;
};

A<A<int> >::X::X i;

Is a fix available for this problem ?

It's not template related. A code:

class A
{
public:
typedef int X;
};

class B
{
public:
typedef A X;
};

B::X::X i;

is not compiled also. It thinks B::X::X is a some constructor's declaration.
typedef however resolves the issue:

typedef B::X BX;

BX::X i;
 
I

Ioannis Vranos

MatthiasBiel said:
Bug ID:FDBK15340 http://lab.msdn.microsoft.com/Produ...edbackid=0b70534f-d613-4878-b55a-0ca3048d901a
for the first problem.

I didn't create a report for the second problem because I don't have
the 2005 beta installed (and VC7.1 can't be selected in the report
form).



I am afraid the bug doesn't make sense.


This one compiles:

template<class T>
class A {
public:
typedef T X;
};

A<A<int>::X>::X i;

int main()
{
}



C:\c>cl /clr temp.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.40904
for Microsoft (R) .NET Framework version 2.00.40607.16
Copyright (C) Microsoft Corporation. All rights reserved.

temp.cpp
Microsoft (R) Incremental Linker Version 8.00.40904
Copyright (C) Microsoft Corporation. All rights reserved.

/out:temp.exe
temp.obj

C:\c>


If we replace A<int> with Type1 and A<Type1> with Type 2, it becomes:


Type2::X::X i;


being equivalent to:


Type2::Type1::X i;



Following that, I checked this and doesn't compile too:


class A
{
public:
typedef int X;
};


class B
{
public:
typedef A X;
};


int main()
{
B::X::X i;
}



C:\c>cl /clr temp.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.40904
for Microsoft (R) .NET Framework version 2.00.40607.16
Copyright (C) Microsoft Corporation. All rights reserved.

temp.cpp
temp.cpp(17) : error C2146: syntax error : missing ';' before identifier 'i'
temp.cpp(17) : error C3867: 'A::{ctor}': function call missing argument
list; use '&A::{ctor}' to create a pointer to member
temp.cpp(17) : error C2065: 'i' : undeclared identifier

C:\c>
 
M

MatthiasBiel

Ioannis Vranos said:
I am afraid the bug doesn't make sense.
I'm not perfectly sure about that ;-)
The original code compiles both with GCC 3.3.1 and the Comeau online
compiler.
The question is: Do GCC and Comeau compile more than the standard
allows or does VC compile less ? I'd currently vote for the latter.
Besides of that, I hit the problem while writing real code, in a
situation where your workaround was not applicable.
 
I

Ioannis Vranos

MatthiasBiel said:
I'm not perfectly sure about that ;-)
The original code compiles both with GCC 3.3.1 and the Comeau online
compiler.
The question is: Do GCC and Comeau compile more than the standard
allows or does VC compile less ? I'd currently vote for the latter.
Besides of that, I hit the problem while writing real code, in a
situation where your workaround was not applicable.



This was a follow-up that strangely did not appear:


Ioannis said:
I am afraid the bug doesn't make sense.



That one was a left over. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top