This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: explicit instantiation: function vs. class
Giovanni Bajo wrote:
>> namespace serialization {
>>
>> template<class T, class Seq>
>> void
>> boost_template_instantiate(T &,Seq &) {}
>> }
>>
>> namespace X
>> {
>> class C {};
>>
>> template
>> void
>> serialization::boost_template_instantiate<>(X::C &, int &);
>> }
>
>> export4.cpp:26: error: declaration of `void
>> boost_template_instantiate(X::C&,
>> int&)' not in a namespace surrounding `serialization'
>>
>> The questions are:
>>
>> 1. Why the error? I could not find anything in the standard. It say
>> that explicit specialization should be declared in the same
>> namespace, but I see no restriction for instantiation.
>
> I think the error is bogus. I cannot find evidence in the standard that
> the explicit instantiation should be rejected because it happens in a
> different scope.
I've just with online Comeau, and it has objections to the code as well:
"ComeauTest.c", line 25: error: function
"serialization::boost_template_instantiate(T &, Seq &) [with
T=X::C,
Seq=int]" cannot be explicitly instantiated in the current scope
serialization::boost_template_instantiate<>(X::C &, int &);;
Interesting, why such bug occurs in two compilers.
>> 2. Why the error happens for function only? The class is instantiated
>> just fine.
>
> This is a bug in GCC. Please, file a bug report in Bugzilla.
Sure. I think I'd check with comp.std.c++ first, to make sure it's really
legal code.
- Volodya