* explicit instantiation: function vs. class
@ 2004-03-17 15:29 Vladimir Prus
2004-03-17 16:40 ` Giovanni Bajo
0 siblings, 1 reply; 3+ messages in thread
From: Vladimir Prus @ 2004-03-17 15:29 UTC (permalink / raw)
To: gcc
Hello,
I have a problem where explicit instantiation of a class works, but for a
function does not. Consider the following example:
namespace serialization {
template<class T>
class helper {};
template<class T, class Seq>
void
boost_template_instantiate(T &,Seq &) {}
}
namespace X
{
class C {};
template
void
serialization::boost_template_instantiate<>(X::C &, int &);
template
class serialization::helper<int>;
}
Using gcc version 3.3.3 20040125 (prerelease) (Debian) I get:
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.
2. Why the error happens for function only? The class is instantiated just
fine.
Thanks,
Volodya
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: explicit instantiation: function vs. class
2004-03-17 15:29 explicit instantiation: function vs. class Vladimir Prus
@ 2004-03-17 16:40 ` Giovanni Bajo
2004-03-18 10:45 ` Vladimir Prus
0 siblings, 1 reply; 3+ messages in thread
From: Giovanni Bajo @ 2004-03-17 16:40 UTC (permalink / raw)
To: gcc, Vladimir Prus
Vladimir Prus wrote:
> namespace serialization {
>
> template<class T>
> class helper {};
>
> template<class T, class Seq>
> void
> boost_template_instantiate(T &,Seq &) {}
> }
>
> namespace X
> {
> class C {};
>
> template
> void
> serialization::boost_template_instantiate<>(X::C &, int &);
>
> template
> class serialization::helper<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.
> 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.
Giovanni Bajo
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: explicit instantiation: function vs. class
2004-03-17 16:40 ` Giovanni Bajo
@ 2004-03-18 10:45 ` Vladimir Prus
0 siblings, 0 replies; 3+ messages in thread
From: Vladimir Prus @ 2004-03-18 10:45 UTC (permalink / raw)
To: gcc
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-03-18 10:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-17 15:29 explicit instantiation: function vs. class Vladimir Prus
2004-03-17 16:40 ` Giovanni Bajo
2004-03-18 10:45 ` Vladimir Prus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).