Connecting Tech Pros Worldwide Forums | Help | Site Map

VC 7.1 Bug related to templates ?!

MatthiasBiel
Guest
 
Posts: n/a
#1: Nov 17 '05
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

David Lowndes
Guest
 
Posts: n/a
#2: Nov 17 '05

re: VC 7.1 Bug related to templates ?!


>Microsoft Visual C++ .NET 69586-112-0293626-18840[color=blue]
>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 ?[/color]

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
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
MatthiasBiel
Guest
 
Posts: n/a
#3: Nov 17 '05

re: VC 7.1 Bug related to templates ?!


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
David Lowndes
Guest
 
Posts: n/a
#4: Nov 17 '05

re: VC 7.1 Bug related to templates ?!


>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
MatthiasBiel
Guest
 
Posts: n/a
#5: Nov 17 '05

re: VC 7.1 Bug related to templates ?!


> Can you post the link to your report back here and I'll add a vote to[color=blue]
> it since I can repro it.[/color]
Bug ID:FDBK15340 http://lab.msdn.microsoft.com/Produc...a-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).

cheers

Matthias
Vladimir Nesterovsky
Guest
 
Posts: n/a
#6: Nov 17 '05

re: VC 7.1 Bug related to templates ?!


> template<class T>[color=blue]
> class A {
> public:
> typedef T X;
> };
>
> A<A<int> >::X::X i;
>
> Is a fix available for this problem ?[/color]

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;
--
Vladimir Nesterovsky
e-mail: vladimir@nesterovsky-bros.com
home: www.nesterovsky-bros.com


Ioannis Vranos
Guest
 
Posts: n/a
#7: Nov 17 '05

re: VC 7.1 Bug related to templates ?!


MatthiasBiel wrote:
[color=blue]
> Bug ID:FDBK15340 http://lab.msdn.microsoft.com/Produc...a-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).[/color]



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>



--
Ioannis Vranos
MatthiasBiel
Guest
 
Posts: n/a
#8: Nov 17 '05

re: VC 7.1 Bug related to templates ?!


Ioannis Vranos <ivr@guesswh.at.grad.com> wrote in message[color=blue]
> I am afraid the bug doesn't make sense.[/color]
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.
Ioannis Vranos
Guest
 
Posts: n/a
#9: Nov 17 '05

re: VC 7.1 Bug related to templates ?!


MatthiasBiel wrote:
[color=blue]
> 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.[/color]



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


Ioannis Vranos wrote:
[color=blue]
> I am afraid the bug doesn't make sense.[/color]



That one was a left over. :-)



--
Ioannis Vranos
Closed Thread