|
![](/i/fill.gif) |
Fredrik Eriksson <fe79}--at--{yahoo}--dot--{com> wrote:
> > I have to admit I don't know if the C++ standard requires the
> > environment of the instantation of the template when compiling the
> > template function or not.
> 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. 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.
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.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |