Possible bug in explicit template specialization

Roman Levenstein romix@geocities.com
Tue Jun 6 03:49:00 GMT 2000


Hi,

I think, I've found a bug in g++.

Here is the source code(it's a part of an library):

template <class E>
class A
{
public:
   A(){}

   A& assign(E const & obj); // do I need to add "export" here?

   A& operator=(E const & obj)
   {
      assign(obj);  
   }
};

void dummy_func()
{
   A< int > obj; 
   obj=4;
   obj.assign(5); // first instantiation?
}

// #1 <- error message 
A<int>& A<int>::assign(int const & obj)
{
  // code of assign
}



Compiler gives the following error messages:

templ.cpp:24: specialization of A<int>::assign(const int &) after
instantiation
templ.cpp:24: explicit specialization of A<int>::assign(const int &)
after first use

I've got the same messages from both gcc-2.95.2 and  gcc-2.96.20000605.
(And Sun C++ compiler compiles it without problems, according to the
author of this library)

The problem is that I can't place the code of assign() before
dummy_func,
because they are placed in different source files in the library and the
code above was produced by preprocessor. It would be rather difficult to
correct all such declarations in all library files. 

Even if it's not an error, but a correct behavior of gcc, I'd like to
know, what is being instantiated at obj.assign(5) as a body of assign()?
As I understand it's not defined at that place. But then it's not clear
, why can't 
I define assign later?

Can "export" help in this situation?

Roman Levenstein


More information about the Gcc-bugs mailing list