473,407 Members | 2,359 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,407 software developers and data experts.

Question about dependent names and typename

Is the following code legal C++?

template <class T >
class C {
class Nested {
C<T>::Nested *n; // typename???
};
};

My understanding was that C<T>::Nested should be considered a dependent
name so should have typename before it. Both MSVC and GCC fail with
errors like "missing ; before *" which seems to confirm my suspicions.
However, Comeau's online C++ compiler lets it pass successfully, which
makes me question the correctness considering Comeau's reputation as
being compliant.

So is this a quirk of Comeau that they let this through because it's
commonly (mis-)used idiom, or is this GCC and MSVC failing to let
through something they should? Or is the standard ambiguous and they
are just interpreting it differently?

(Comeau also lets through the code with a typename. But I also thought
that in all cases typename was either required or prohibited (so never
optional), which would seem to say that Comeau has to be wrong one way
or the other.)

Nov 28 '06 #1
3 1319

Evan napsal:
Is the following code legal C++?

template <class T >
class C {
class Nested {
C<T>::Nested *n; // typename???
};
};

My understanding was that C<T>::Nested should be considered a dependent
name so should have typename before it. Both MSVC and GCC fail with
errors like "missing ; before *" which seems to confirm my suspicions.
However, Comeau's online C++ compiler lets it pass successfully, which
makes me question the correctness considering Comeau's reputation as
being compliant.

So is this a quirk of Comeau that they let this through because it's
commonly (mis-)used idiom, or is this GCC and MSVC failing to let
through something they should? Or is the standard ambiguous and they
are just interpreting it differently?

(Comeau also lets through the code with a typename. But I also thought
that in all cases typename was either required or prohibited (so never
optional), which would seem to say that Comeau has to be wrong one way
or the other.)
I think there should be typename. Anyway, I would write it as

template <class T >
class C
{
class Nested
{
Nested *n;
};
};

Nov 28 '06 #2

Evan wrote:
Is the following code legal C++?

template <class T >
class C {
class Nested {
C<T>::Nested *n; // typename???
};
};
You definitely need a typename for sure.
But doesnt the above C<T>::Nested form the non deduced context, which
means T cannot be deduced for these constructs ?
>
My understanding was that C<T>::Nested should be considered a dependent
name so should have typename before it. Both MSVC and GCC fail with
errors like "missing ; before *" which seems to confirm my suspicions.
However, Comeau's online C++ compiler lets it pass successfully, which
makes me question the correctness considering Comeau's reputation as
being compliant.

So is this a quirk of Comeau that they let this through because it's
commonly (mis-)used idiom, or is this GCC and MSVC failing to let
through something they should? Or is the standard ambiguous and they
are just interpreting it differently?

(Comeau also lets through the code with a typename. But I also thought
that in all cases typename was either required or prohibited (so never
optional), which would seem to say that Comeau has to be wrong one way
or the other.)
Nov 28 '06 #3
am******@gmail.com wrote:
Evan wrote:
Is the following code legal C++?

template <class T >
class C {
class Nested {
C<T>::Nested *n; // typename???
};
};

You definitely need a typename for sure.
But doesnt the above C<T>::Nested form the non deduced context, which
means T cannot be deduced for these constructs ?
I have no clue what this even means. :-)

This situation arose because I'm trying to do source-to-source
transformation of C++, and the tool that I'm doing is very buggy. (I
think that this is the first time that the pretty-printing feature has
really been exercised; it's fairly new, and the previous work that's
been done one it has been analyses, so no output required.) A version
of the above where the "C<T>::" was removed (to give what the other
poster suggested, and what most people would write) currently outputs
as the above. I needed to find out if this was an error, partly so I
know how to fix it but mostly just for curiosity.

Thanks for your response (and to the other person who replied and
anyone else who does so in the future with more clarifications or
anything)

Evan
>

My understanding was that C<T>::Nested should be considered a dependent
name so should have typename before it. Both MSVC and GCC fail with
errors like "missing ; before *" which seems to confirm my suspicions.
However, Comeau's online C++ compiler lets it pass successfully, which
makes me question the correctness considering Comeau's reputation as
being compliant.

So is this a quirk of Comeau that they let this through because it's
commonly (mis-)used idiom, or is this GCC and MSVC failing to let
through something they should? Or is the standard ambiguous and they
are just interpreting it differently?

(Comeau also lets through the code with a typename. But I also thought
that in all cases typename was either required or prohibited (so never
optional), which would seem to say that Comeau has to be wrong one way
or the other.)
Nov 28 '06 #4

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

Similar topics

5
by: derek | last post by:
(Message also posted to comp.std.c++) I have just been experimenting with g++ 3.4 and code that I thought was compliant has raised compiler problems. Basically, if we have the following code: ...
4
by: Ana Farcas via .NET 247 | last post by:
hello, i have an old library i need to port to .net. the old library is written in visual c++ 6.0 and uses templated classes. if i compile the library (after having gone through the conversion...
2
by: adebaene | last post by:
Hello all, I just checked that the following did compile with VC2005 b2, and I think it shouldn't: template <typename T> struct A { typedef int Foo; };
3
by: chriscorbell | last post by:
I'm curious about what appears to be a restriction on using an STL container inside a user-defined template, esp. using an iterator to such a container. It's not clear to me if this is a general...
2
by: sharpblade | last post by:
The title of these Item is "Make header files self-sufficient" There're two examples in this Item: Example 1: Dependent names. Templates are compiled at the point where they are defined, except...
0
by: Jim Avera | last post by:
On AIX, a template class containing a nested class which needs to be a friend provokes a warning: (W) A template dependent name that is a type must be qualified with "typename". and method...
3
by: mojmir | last post by:
Good morning, i found small difference between gcc and visual studio when looking up a dependent name. Consider: struct Base { template<typename T, typename U> void Implement (T t) { } };
5
by: Christof Warlich | last post by:
Hi, just being curious: Anyone having a clue why the commented lines do not compile? Thanks, Christof class B {
54
by: shuisheng | last post by:
Dear All, I am always confused in using constants in multiple files. For global constants, I got some clues from http://msdn.microsoft.com/en-us/library/0d45ty2d(VS.80).aspx So in header...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.