summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiateDecl.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 6936539f1ca..014400822c3 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3865,6 +3865,17 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation,
if (TSK == TSK_ExplicitInstantiationDeclaration)
return;
+ // We may be explicitly instantiating something we've already implicitly
+ // instantiated.
+ VarDecl *InstantiatedDef = Var->getDefinition();
+ if (InstantiatedDef)
+ InstantiatedDef->setTemplateSpecializationKind(TSK, PointOfInstantiation);
+
+ // If we've already instantiated the definition and we're not
+ // re-instantiating it explicitly, we don't need to do anything.
+ if (InstantiatedDef && TSK != TSK_ExplicitInstantiationDefinition)
+ return;
+
// Make sure to pass the instantiated variable to the consumer at the end.
struct PassToConsumerRAII {
ASTConsumer &Consumer;
@@ -3878,14 +3889,10 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation,
}
} PassToConsumerRAII(Consumer, Var);
- // If we already have a definition, we're done.
- if (VarDecl *Def = Var->getDefinition()) {
- // We may be explicitly instantiating something we've already implicitly
- // instantiated.
- Def->setTemplateSpecializationKind(Var->getTemplateSpecializationKind(),
- PointOfInstantiation);
+ // If we already implicitly instantiated this, just let the consumer know that
+ // it needs to handle an explicit instantiation now.
+ if (InstantiatedDef && TSK == TSK_ExplicitInstantiationDefinition)
return;
- }
InstantiatingTemplate Inst(*this, PointOfInstantiation, Var);
if (Inst.isInvalid())
OpenPOWER on IntegriCloud