Watch, Follow, &
Connect with Us
Public Report
Report From: C++BuilderX/Compiler/Front end/bcc32/templates    [ Add a report in this area ]  
Report #:  14110   Status: Open
specializing variables fails
Project:  C++BuilderX/BC++ 2005 Build #:  1.8.0.328
Version:    1.5 Submitted By:   Thomas Neumann
Report Type:  Basic functionality failure Date Reported:  7/3/2005 8:17:11 AM
Severity:    Infrequently encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   240033
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (1 Total Rating)
5.00 out of 5
Total Votes: 3
Description
Specializing a variable inside a template class fails when providing two specializations (for different template parameters). Specializing once works. See steps for an example.
Steps to Reproduce:
Compile the following program with bcc32 test.cpp:

struct A {
   const A* a;
};

template <const char* c> struct B {
   static const A b;
};

extern const char c[1]="";
extern const char d[1]="";

//I found out that the standard requires a declaration of the specialization before usage,
//so the following two lines:

template<> const A B<c>::b;
template<> const A B<d>::b;

//have to inserted before the last two lines.
//However bcc32 accepts the code neither with nor without declaration.
//Gcc accepts both versions, Comeau and icc require the declaration and
//Microsoft only accepts the code without declaration.
//The C++ standard mandates the declarations.

template<> const A B<c>::b = {&B<d>::b};
template<> const A B<d>::b = {&B<c>::b};

Workarounds
None
Attachment
None
Comments

Thomas Neumann at 7/7/2005 1:33:59 PM -
I found out that the standard requires a declaration of the specialization before usage, so the following two lines

template<> const A B<c>::b;
template<> const A B<d>::b;

have to inserted before the last two lines. However bcc32 accepts the code neither with nor without declaration.

Gcc accepts both versions, Comeau and icc require the declaration and Microsoft only accepts the code without declaration. The C++ standard mandates the declarations.

Server Response from: ETNACODE01