rsmith added inline comments.

================
Comment at: lib/Sema/Sema.cpp:189
+
+  Context.setInstantiator(new SemaTemplateInstantiator(*this));
 }
----------------
It's not correct/reasonable to instantiate whenever an expression happens to be 
evaluated, in numerous ways:

1) You'll get the "point of instantiation" wrong -- the standard only permits 
instantiation (as-if) immediately at the point of use or at the end of the 
translation unit
2) You risk instantiating at some points where no instantiation is permitted at 
all -- for instance, if SemaChecking decides it wants to try to evaluate some 
expression to produce a warning, and the code it tries to evaluate happens to 
be in an unevaluated operand, you are not permitted to instantiate things it 
references.
3) It risks making the set of instantiations / effective points of 
instantiation dependent on the warning flags that happen to be in effect, since 
existing code may or may not choose to evaluate an expression depending on 
warning flags.

Fundamentally, either constant expression evaluation needs to be side-effect 
free, or we need to distinguish between places where we happen to evaluate 
things and places where we evaluate things because the language requires them 
to be constant expressions. The current direction of CWG1581 is to make the 
"should we instantiate?" determination based solely on the syntactic context, 
which means that the constant expression evaluator should never trigger any 
instantiations.

In order to fix the case where a function/variable template specialization that 
is usable in a constant expression is defined after the point of use, I think 
we should check for pending instantiations of that function / variable template 
when we complete its definition, and perform those instantiations at that time.


https://reviews.llvm.org/D36353



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D36353: I... Serge Pavlov via Phabricator via cfe-commits
    • [PATCH] D363... Richard Smith - zygoloid via Phabricator via cfe-commits
    • [PATCH] D363... Serge Pavlov via Phabricator via cfe-commits
    • [PATCH] D363... Richard Smith - zygoloid via Phabricator via cfe-commits

Reply via email to