Topic: Multiple explicit instantiations?


Author: dsp@bdal.de (Daniel Spangenberg)
Date: Mon, 21 Jul 2003 18:32:47 +0000 (UTC)
Raw View
Our Holy Standard claims in 14.7.2/4:

"The definition of a non-exported function template, a non-exported
member
function template, or a non-exported member function or static data
member
of a class template shall be present in every translation unit in which
it is
explicitly instantiated."

I am wondering concerning this description,because it seems to imply,
that
more than one explicit instantiation for the same class (function, ...)
in
the program are OK. But this implication contradicts to 14.7/5, which
says,
that

"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."

Can someone enlighten me? Most probably it is my bad english, which
makes
me interpreting 14.7.2/4 to mean, that these translation units might be
part of the same program?!

Thanks,

Daniel Spangenberg



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: google@vandevoorde.com (Daveed Vandevoorde)
Date: Tue, 22 Jul 2003 22:56:55 +0000 (UTC)
Raw View
dsp@bdal.de (Daniel Spangenberg) wrote:> Our Holy Standard claims in 14.7.2/4:
>
> "The definition of a non-exported function template, a non-exported
> member
> function template, or a non-exported member function or static data
> member
> of a class template shall be present in every translation unit in which
> it is
> explicitly instantiated."
>
> I am wondering concerning this description,because it seems to imply,
> that more than one explicit instantiation for the same class (function, ...)
> in> the program are OK.
[...]

Not really.  It just takes into account the fact that a same _template_
(or member thereof) can be instantiated in multiple translation units.

For example:

    // TU1:
    template<typename T> void f() {}
    template void f<void>;

    // TU2:
    template<typename T> void f() {}
    template void f<int*>;

These are fine.  But the following:

    // TU3:
    template<typename T> void f();
    template void f<bool>;  // Error: missing definition of f.

is not.

        Daveed

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]