|
![](/i/fill.gif) |
On Fri, 16 May 2008 15:16:07 +0200, Warp <war### [at] tag povray org> wrote:
> Fredrik Eriksson <fe79}--at--{yahoo}--dot--{com> wrote:
>> When parsing the template definition, only non-dependent names are
>> looked
>> up. Dependent names are looked up at the instantiation point; at that
>> point both contexts are needed.
>
> Actually that's not what the C++ standard says.
Oh yes it is. Check sections 14.6.3 & 14.6.4.
> This is the relevant part of the standard:
>
> A specialization for a function template, a member
> function template, or of a member function or static
> data member of a class template may have multiple points
> of instantiations within a translation unit. A
> specialization for a class template has at most one
> point of instantiation within a translation unit. A
> specialization for any template may have points of
> instantiation in multiple translation units. If two
> different points of instantiation give a template
> specialization different meanings according to the one
> definition rule (3.2), the program is ill-formed, no
> diagnostic required.
>
> In short: If the context causes a template instantiation to produce
> different results, the program is ill-formed. In other words, the
> result is undefined behavior, and the compiler can do whatever it wants.
What the paragraph (from section 14.6.4.1) says is that if a particular
template specialisation is instantiated in more than one place then those
instantiations must have the same meaning.
In the example I posted there is only one instantiation point for 'f'; the
ODR is irrelevant there.
> I understand this to also mean that the compiler is allowed to compile
> an export template just once even if it's instantiated at several places,
> using the context of one of those places.
Only if all those places use the exact same template specialisation. Note
that this would require the compiler/linker to remember which translation
units use which exported templates, since the exported template must still
be recompiled if all of the relevant contexts change. Also note that the
linker would have to verify that at least one of the translation units
having an "unchanged" context actually gets linked in; if not, the
template would have to be recompiled.
--
FE
Post a reply to this message
|
![](/i/fill.gif) |