C1001 at msc1.cpp:2701 when specializing template member

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

VC 7.1.3088 Bug: When a class defines a template member function taking (T const &),
then an explicit specialization taking a non-const & argument (U) causes a C1001 at msc1.cpp line 2701.

The following short program duplicates this error.
Compile it in Debug mode (all optimizations disabled), with "Not using precompiled headers".

Class C defines F as a template member function taking (_T const &).
It then specializes F taking a char.
a) If the specialization signature is (char const &), it compiles OK.
b) If the specialization signature is (char) or (char &), it fails with a C1001.

VC6 and VC7.0 compile (b) without any problems.
 
Eric said:
VC 7.1.3088 Bug: When a class defines a template member function
taking (T const &),
then an explicit specialization taking a non-const & argument (U)
causes a C1001 at msc1.cpp line 2701.

The following short program duplicates this error.

Did you intend to include the short program?

-cd
 
Did you intend to include the short program?

Very damn frustrating.
I've tried posting my program 8 times. The server gives an error every time.

I shorten my program from 10 lines to 8, to 6, to 5. Error, error, error.
I shortened it to 1 line. That worked.

Does the server accept only 1 line of C++ code per post?
Does it choke on curly brace, semicolon, or other C++ characters?
 
ALERT: CHANGE ALL [ to angleopen, ] to angleclose. (I had to do this to get the server to accept this post.)
---- begin foo.cpp ----
class C
{
public:
template[typename _T] void F(_T const &);
template[] void F(char
// Comment out the following line to generate a C1001 at msc1.cpp:2701.
const &
);
};

void main(void) { C c; c.F('a'); }
---- end foo.cpp ----
 
I could not post my C++ code containing angle brackets in standard template notation.
I kept getting:

Server Error in '/library' Application.
 
Eric said:
Very damn frustrating.
I've tried posting my program 8 times. The server gives an error
every time.

I think it's a problem with posting through the web-based newsreader. If
you use an NNTP client (Outlook Express, Forte Agent, etc), then you can
post C++ source code with no problems.

-cd
 
Eric said:
ALERT: CHANGE ALL [ to angleopen, ] to angleclose. (I had to do this
to get the server to accept this post.)
---- begin foo.cpp ----
class C
{
public:
template[typename _T] void F(_T const &);
template[] void F(char
// Comment out the following line to generate a C1001 at
msc1.cpp:2701. const &
);
};

void main(void) { C c; c.F('a'); }
---- end foo.cpp ----

I was able to reproduce your ICE. Unfortunately, this code is not valid
C++: According to the C++ standard, you're not allowed to explicitly
specialize a template member function inline in the class definition.

Move your specialization out of the class definition and it's both legal
C++, and VC7.1 will compile it:

class C
{
public:
template<typename _T> void F(_T const &);
};

template<> void C::F(char const &)
{
}

int main()
{
C c;
c.F('a');
}

-cd
 
Back
Top