This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

2.95.4 compiler error with template specialization?


Hola~

I believe this is a bug in g++. I am able to compile the following code using
sgi's CC and Kai's KCC:

      1 //
      2 // test of using a const std::string initializer
      3 //
      4 
      5 #include <string>
      6 
      7 template<class T> struct A {
      8     T t;
      9     static int i;
     10     static const std::string s;
     11 };
     12 
     13 typedef A<int> IntA;
     14 template<> int IntA::i;
     15 template<> int IntA::i = 4;
     16 template<> const std::string IntA::s;
     17 template<> const std::string IntA::s = "Hiya";
     18 
     19 int main() {
     20 
     21         return 0;
     22 }

produces the following:

    % g++ t382.cpp 
    t382.cpp:17: conflicting types for `const class string A<int>::s'
    t382.cpp:16: previous declaration as `class basic_string<char,string_char_traits<char>,__default_alloc_template<true,0> > A<int>::s'

This is a simple test that replicates the problem. It compiles fine without
the declaration at line 6. However, KCC requires the forward declaration of
template specialization members.

I want to know why the declaration at line 17 thinks "s" is a "const class
string" instead of a "const basic_string<...>"?

MO

-- 
Michael O'Brien                                                         Tools
Pixar                                                       mobrien@pixar.com

VIZZINI: You fell victim to one of the classic blunders. The most famous is 
         never get involved in a land war in Asia. But only slightly less 
         well-known is this: never go in against a Sicilian when death is on
         the line. Ha ha ha ha ha ha. Ha ha ha ha ha--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]