473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

VC 7.1 Bug related to templates ?!

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
Nov 17 '05 #1
8 1010
>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
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 17 '05 #2
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
Nov 17 '05 #3
>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
Nov 17 '05 #4
> Can you post the link to your report back here and I'll add a vote to
it since I can repro it.

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
Nov 17 '05 #5
> template<class T>
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;
--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
home: www.nesterovsky-bros.com
Nov 17 '05 #6
MatthiasBiel wrote:
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).


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
Nov 17 '05 #7
Ioannis Vranos <iv*@guesswh.at.grad.com> wrote in message
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.
Nov 17 '05 #8
MatthiasBiel wrote:
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 Vranos wrote:
I am afraid the bug doesn't make sense.


That one was a left over. :-)

--
Ioannis Vranos
Nov 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: Niels Berkers | last post by:
Hi, i'd like to host my web pages using multiparts to reduce the number of hits on the server. i know this isn't a real PHP subject, but i'll try it anyway. i've been searching the web for...
2
by: Karthik D | last post by:
Hello All, I am a newbie to C++ code particularly templates.Below is a template class defintion and I couldn't find the ObjPtr/ObjFnPtr class definition anywhere in source code. template<class...
5
by: Tom Alsberg | last post by:
Hi there... I'm recently trying to get a bit acquainted with XML Schemas and XSL. Now, I have a few questions about XSL stylesheets and templates: * Is there a way to "enter" a child element...
1
by: Vijay singh | last post by:
Hi wonder if anybody can clear by doubt XML file : <score id="1"> <film>A Little Princess</film> <composer>Patrick Doyle</composer>
5
by: Mohammad | last post by:
Hi, Is it possible to disable a method of a template class depending on the typename at compile time? thanks!
3
by: bonj | last post by:
Hello How do I declare a template class such that the template class T must implement a certain interface? e.g. interface IProvideID { int MyID; };
5
by: hilz | last post by:
Hi all I have this situation where I have an xml file similar to this: <Root> <MyElement year="2004"><Amount>10</Amount></MyElement> <MyElement year="2004"><Amount>11</Amount></MyElement>...
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
4
by: noone | last post by:
Hi. I've got a fella working for me who is trying to convince me to change our coding standards to using separate .h and .cc files for definitions and implementations. I know this is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.