Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / September 2005

Tip: Looking for answers? Try searching our database.

typename

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Staffan Langin - 29 Aug 2005 13:46 GMT
Hello,

In the following code-snippet,

template<class Base>

class Foo : public Base

{

typedef typename Base::Type Type;    //1

Type FooBar();

};

template<class Base> typename Foo<Base>::Type    //2

Foo<Base>::FooBar()

{

return 0;

}

struct Bar {typedef int Type;};

template class Foo<Bar>;

The C++ standard requires the typename at 1 but not at 2. However, the
compiler included in Visual Studio 2005 also requires typename at 2
resulting in a LOT of errors in my current project. Is this a known problem
that is scheduled to be fixed in the release version of VS2005?

Staffan Langin
Derrick Coetzee [MSFT] - 30 Aug 2005 18:59 GMT
> template<class Base>
> class Foo : public Base {
[quoted text clipped - 8 lines]
> compiler included in Visual Studio 2005 also requires typename at 2
> resulting in a LOT of errors in my current project.

I'm not confident that you're correct about (2) being allowed by the
standard without a "typename" keyword. The type Foo<Base>::Type is clearly a
dependent type on the template parameter Base, and section 14.6.3 of the ISO
C++ standard says:

"A qualified-name that refers to a type and that depends on a
template-parameter (14.6.2) shall be prefixed by the keyword typename to
indicate that the qualified-name denotes a type, forming an
elaborated-type-specifier (7.1.5.3)."

Because Foo<Base>::Type is a qualified type name (it uses ::), this seems to
mandate the keyword. Paragraphs 5 and 6 reinforce this:

"The keyword typename shall only be used in template declarations and
definitions, including [...] in the return type for the definition of a
member function of a class template [...]" (this para allows but does not
require its use here)

"Within the definition of a class template or within the definition of a
member of a class template, [...] [t]he keyword typename shall always be
specified when the member is referred to using a qualified name, even if the
qualifier is simply the class template name."

For comparison, this (more or less) equivalent code compiles cleanly,
because it uses an unqualified type name, even though the type Type is still
dependent:

template<class Base>
class Foo : public Base {
   typedef typename Base::Type Type;
   Type FooBar() {
       return 0;
   }
};

It's possible that your previous compiler was more lenient, or
misinterpreted the standard; previous versions of Visual Studio did allow
one to omit this keyword (according to the MSDN entry for C4346). There
doesn't seem to be any ambiguity in leaving it out, since you can only have
a type name in that position, but the standard seems to require it, if I'm
not misinterpreting it. If you can justify your statement to the contrary
I'd like to hear your argument. I hope this helps.
Signature

Derrick Coetzee, MCP, MSFT (Speech Server)
This posting is provided "AS IS" with no warranties, and confers no
rights.

Staffan Langin - 31 Aug 2005 08:06 GMT
> It's possible that your previous compiler was more lenient, or
> misinterpreted the standard; previous versions of Visual Studio did allow
[quoted text clipped - 3 lines]
> if I'm not misinterpreting it. If you can justify your statement to the
> contrary I'd like to hear your argument. I hope this helps.

Derrick,

If I interpret the defect report,
www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#224, correctly the
name at 2 is a member of the current instantiation and doesn't require the
typename keyword.

Staffan Langin
Derrick Coetzee [MSFT] - 06 Sep 2005 19:26 GMT
>> It's possible that your previous compiler was more lenient, or
>> misinterpreted the standard; previous versions of Visual Studio did
[quoted text clipped - 9 lines]
> the name at 2 is a member of the current instantiation and doesn't
> require the typename keyword.

I apologise - you're correct. I'm afraid I was misinterpreting this portion
of the standard. I hope the workaround of adding the keyword is sufficient
for your purposes (or that you're willing to wait for VS2005 to release).
Sorry about that.
Signature

Derrick Coetzee, MCP, MSFT (Speech Server)
This posting is provided "AS IS" with no warranties, and confers no
rights.

Derrick Coetzee [MSFT] - 06 Sep 2005 19:35 GMT
>>> It's possible that your previous compiler was more lenient, or
>>> misinterpreted the standard; previous versions of Visual Studio did
[quoted text clipped - 14 lines]
> is sufficient for your purposes (or that you're willing to wait for
> VS2005 to release). Sorry about that.

I see what happened now - after reading the item at
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#224 , it seems
that my interpretation was based on the 1998 edition of the C++ standard,
which exhibited this issue. I'll be sure to refer to the most recent version
in the future. Sorry about that.
Signature

Derrick Coetzee, MCP, MSFT (Speech Server)
This posting is provided "AS IS" with no warranties, and confers no
rights.

Staffan Langin - 07 Sep 2005 10:21 GMT
> I see what happened now - after reading the item at
> http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#224 , it
> seems that my interpretation was based on the 1998 edition of the C++
> standard, which exhibited this issue. I'll be sure to refer to the most
> recent version in the future. Sorry about that.

No prb. Actually, the defect report hasn't got TC1-status yet so formally
you are correct :-).

Staffan Langin
David Lowndes - 31 Aug 2005 09:43 GMT
>In the following code-snippet,
>
[quoted text clipped - 15 lines]
>
>The C++ standard requires the typename at 1 but not at 2.

Staffan,

The Comeau online compiler seems to agree.

> However, the
>compiler included in Visual Studio 2005 also requires typename at 2
>resulting in a LOT of errors in my current project. Is this a known problem
>that is scheduled to be fixed in the release version of VS2005?

It's no different in the Aug CTP release, the compiler gives these
errors without typename:

warning C4346: 'Foo<Base>::Type' : dependent name is not a type   
error C2143: syntax error : missing ';' before 'Foo<Base>::FooBar'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
fatal error C1903: unable to recover from previous error(s); stopping
compilation

I suggest that you report it as a bug here:

http://lab.msdn.microsoft.com/productfeedback/default.aspx

and post a link back here to your bug report and I'll add a
confirmation vote to it.

Dave
Signature

MVP VC++ FAQ: http://www.mvps.org/vcfaq

Staffan Langin - 01 Sep 2005 18:27 GMT
> I suggest that you report it as a bug here:
>
> http://lab.msdn.microsoft.com/productfeedback/default.aspx
>
> and post a link back here to your bug report and I'll add a
> confirmation vote to it.

David,

Thanks for your help. I've submitted a bug report now,

http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=46f71
a7e-0675-4223-928a-902187eae8b1


Staffan Langin
David Lowndes - 01 Sep 2005 21:39 GMT
>Thanks for your help. I've submitted a bug report now,
>
>http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=46f71
a7e-0675-4223-928a-902187eae8b1

I see Jonathan Caves has already replied to the report - I've added a
further note to see if he'll clarify this - it'd be nice to know that
he can reproduce it on an earlier build of the compiler, and that it's
now definitely resolved.

Dave
Signature

MVP VC++ FAQ: http://www.mvps.org/vcfaq

Staffan Langin - 02 Sep 2005 08:50 GMT
> I see Jonathan Caves has already replied to the report - I've added a
> further note to see if he'll clarify this - it'd be nice to know that
> he can reproduce it on an earlier build of the compiler, and that it's
> now definitely resolved.

If that's the case, I'd be very pleased. BTW, when can one expect the
release version of VS2005?

Staffan
David Lowndes - 02 Sep 2005 09:11 GMT
>If that's the case, I'd be very pleased. BTW, when can one expect the
>release version of VS2005?

I think it's been publically stated to be available sometime around
the beginning of Nov.

Dave
Signature

MVP VC++ FAQ: http://www.mvps.org/vcfaq

Carl Daniel [VC++ MVP] - 06 Sep 2005 20:04 GMT
>> I see Jonathan Caves has already replied to the report - I've added a
>> further note to see if he'll clarify this - it'd be nice to know that
[quoted text clipped - 3 lines]
> If that's the case, I'd be very pleased. BTW, when can one expect the
> release version of VS2005?

Nov 7, 2005

-cd
Carl Daniel [VC++ MVP] - 06 Sep 2005 20:16 GMT
>> Thanks for your help. I've submitted a bug report now,
>>
[quoted text clipped - 4 lines]
> he can reproduce it on an earlier build of the compiler, and that it's
> now definitely resolved.

I don't think it's fixed.  Rather, I think Jonathan probably tried to
compile the code as-is, saw that it compiled, and assumed it was fixed (the
code as-posted has the extra 'typename' already).

I tested it on build 14.00.50727.24, which dates from less than a week ago
and nothing had changed.

I'd suggest re-activating the case on Product Feedback Center - although I'd
be very surprised if they fix it this late in the release cycle.

-cd
David Lowndes - 06 Sep 2005 23:54 GMT
>I don't think it's fixed.

That was my suspicion too.

>I tested it on build 14.00.50727.24, which dates from less than a week ago
>and nothing had changed.

I've requested it be re-opened.

>I'd suggest re-activating the case on Product Feedback Center - although I'd
>be very surprised if they fix it this late in the release cycle.

Yeah, they won't even add pragamas to header files to eliminate
warnings that the new static analyser picks up on at this stage. :(

Dave
Signature

MVP VC++ FAQ: http://www.mvps.org/vcfaq


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.