Boost logo

Boost :

From: Christoph Ludwig (cludwig_at_[hidden])
Date: 2005-06-29 10:23:56


On Wed, Jun 29, 2005 at 04:12:17PM +0200, Markus Schöpflin wrote:
> Christoph Ludwig wrote:
> >
> > OK, I overcame my laziness :-) It is 14.7p5:
> >
> > No program shall explicitly instantiate any template more than once, both
> > explicitly instantiate and explicitly specialize a template, or specialize a
> > template more than once for a given set of template arguments.
> > An implementation is not required to diagnose a violation of this rule.
> >
> > I admit I find Vandvoorde's and Josuttis' phrasing much easier to grok.
>
> Duh, I read 14.7.2 and 14.7.3 over and over and I completely missed that
> one.:-(
>
> Hmm, now I'm left wondering how in general to deal with this issue. Would
> this be legal?
>
> ---%<---
> template <class T>
> struct foo {
> static T bar() { static T t; return t; }
> };
>
> template<> foo<int>;
> template int foo<int>::bar();
> --->%--

That can't be correct:
a) You mix an explicit specialization of foo with the explicit instantiation
   of its member bar. But explicit instantiation and specialization do not go
   together.

b) You forward declare the explicit specialization of foo<int>. (Is 'forward
   declaration' the right technical term? Anyway, you understand what I mean,
   I hope.) Then you instantiate the member foo<int>::bar. But at this point
   the compiler cannot know whether foo<int> has a member bar at all! It
   cannot refer to the primary template's definition anymore since foo<int> is
   explicitly specialized. OTOH, it did not see the definition of foo<int>
   yet...

Regards

Christoph

-- 
http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/cludwig.html
LiDIA: http://www.informatik.tu-darmstadt.de/TI/LiDIA/Welcome.html

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk