bug in VC++2003

V

Vladimir Petter

Hello,

I am not sure if this bug was noticed before so please ignore posting if it
was.
I was playing with sample from "C++ Templates The Complete Guide" chapter
8.2.4

#include <iostream>

using namespace std;

template <typename T1, typename T2, typename T3=int>
class C;

template <typename T1, typename T2=char, typename T3>
class C;

template <typename T1=long, typename T2, typename T3>
class C{};

void main(){
C<long> c;
cout << typeid(c).name() << endl;
}

Gives following output:
class C<long,long,int>

Expected output was
class C<long,char,int>

If we modify template definition by removing default value for T1:
template <typename T1, typename T2, typename T3>
class C{};
then output is back to normal

Second part of issue is that if all class template arguments have default
values (same sample that gives wrong output) I can not instantiate class
using "C<>". Compiler gives an error that I provided too few parameters.

Of cause this is a minor bug, because I do not see practical reasons to
spread around default values among multiply definitions, but who knows may
be somebody does :)

Regards,
Vladimir.
 
C

Carl Daniel [VC++ MVP]

Vladimir said:
Gives following output:
class C<long,long,int>

Expected output was
class C<long,char,int>

This bug is present in the Whidbey alpha build. I'll make sure it gets
reported as a bug.
If we modify template definition by removing default value for T1:
template <typename T1, typename T2, typename T3>
class C{};
then output is back to normal

Second part of issue is that if all class template arguments have
default values (same sample that gives wrong output) I can not
instantiate class using "C<>". Compiler gives an error that I
provided too few parameters.

This bug is also present in the Whidbey alpha build, so I'll report it as
well.
Of cause this is a minor bug, because I do not see practical reasons
to spread around default values among multiply definitions, but who
knows may be somebody does :)

It is a pretty wierd (and IMO useless) construct, but it's legal according
to the C++ standard. Thanks for the bug reports.

-cd
 

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