Bug 22478 - explicit specialization of template class members
Summary: explicit specialization of template class members
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2005-07-14 07:31 UTC by Wolfgang Roehrl
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i386-pc-mingw32
Target: powerpc-wrs-vxworks
Build: sparc-sun-solaris2.5.1
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Roehrl 2005-07-14 07:31:56 UTC
Dear all,

I would like to post a bug report for the GNU C/C++ compiler 3.3-e500.

We use the compiler to generate code for a PowerPC processor.

Used invokation line for the GNU C++ compiler:

ccppc -c -x c++ -ansi -Wall -Werror -mcpu=8540 -fverbose-asm -mbig
      -fmerge-templates -mmultiple -mno-string -mstrict-align -O3
      -fno-exceptions -fno-rtti -fno-builtin-printf
      -I<different include paths>
      -D<differen #define's>
      X.CPP -oX.O


// file X.CPP

#define MODE 2                      // set MODE to 1 or 2

template <typename T_>
struct S
{
    int f (const T_&) const { return 0; }
    static int s;
};

#if (MODE == 1)

// template <>                      // declaration of S<char>::f
int S<char>::f (const char&) const;

// template <>                      // declaration of S<char>::s
int S<char>::s;

#elif (MODE == 2)

// template <>                      // definition of S<char>::f
int S<char>::f (const char&) const
{ return 1; }

// template <>                      // definition of S<char>::s
int S<char>::s = 2;

#endif


We have a template class S<> whose members should be explicitly specialized
for S<char>.
The program can be translated in two versions: if we set MODE to 1 we only
get a declaration of the specialized members, if we set MODE to 2 we get a
definition of these members.

Set mode to 1: The compiler accepts the declarations without the preceeding
"template<>" phrase. This is not standard compliant (see 14.7.3/1 and
14.7.3/15).

Set mode to 2: The compiler accepts the definitions without the preceeding
"template<>" phrase. This is also not standard compliant (see 14.7.3/16).

Kind regards
W. Roehrl
Comment 1 Wolfgang Bangerth 2005-07-23 20:32:30 UTC
This is already fixed since 3.4. 
 
W.