summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaTemplateInstantiate.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-05-13 20:28:22 +0000
committerDouglas Gregor <dgregor@apple.com>2009-05-13 20:28:22 +0000
commitbbbb02d463066f188c443e2ae7ce9ce5353f8b54 (patch)
tree7e2ff7b99e7e90b827f70d3884dadc87e7d5374c /clang/lib/Sema/SemaTemplateInstantiate.cpp
parent5879fbd933483650c4bb96b9ea7e5c4646b55b98 (diff)
downloadbcm5719-llvm-bbbb02d463066f188c443e2ae7ce9ce5353f8b54.tar.gz
bcm5719-llvm-bbbb02d463066f188c443e2ae7ce9ce5353f8b54.zip
Explicit instantiations of templates now instantiate the definitions
of class members (recursively). Only member classes are actually instantiated; the instantiation logic for member functions and variables are just stubs. llvm-svn: 71713
Diffstat (limited to 'clang/lib/Sema/SemaTemplateInstantiate.cpp')
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiate.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 3a2f6777556..9c2c4230f9c 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -749,6 +749,10 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation,
// Exit the scope of this instantiation.
CurContext = PreviousContext;
+ // If this is an explicit instantiation, instantiate our members, too.
+ if (!Invalid && ExplicitInstantiation)
+ InstantiateClassMembers(PointOfInstantiation, Instantiation, TemplateArgs);
+
return Invalid;
}
@@ -787,6 +791,53 @@ Sema::InstantiateClassTemplateSpecialization(
ExplicitInstantiation);
}
+/// \brief Instantiate the definitions of all of the member of the
+/// given class, which is an instantiation of a class template or a
+/// member class of a template.
+void
+Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation,
+ CXXRecordDecl *Instantiation,
+ const TemplateArgumentList &TemplateArgs) {
+ for (DeclContext::decl_iterator D = Instantiation->decls_begin(Context),
+ DEnd = Instantiation->decls_end(Context);
+ D != DEnd; ++D) {
+ if (FunctionDecl *Function = dyn_cast<FunctionDecl>(*D)) {
+ if (!Function->getBody(Context))
+ InstantiateFunctionDefinition(Function);
+ } else if (VarDecl *Var = dyn_cast<VarDecl>(*D)) {
+ const VarDecl *Def = 0;
+ if (!Var->getDefinition(Def))
+ InstantiateVariableDefinition(Var);
+ } else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(*D)) {
+ if (!Record->isInjectedClassName() && !Record->getDefinition(Context)) {
+ assert(Record->getInstantiatedFromMemberClass() &&
+ "Missing instantiated-from-template information");
+ InstantiateClass(Record->getLocation(), Record,
+ Record->getInstantiatedFromMemberClass(),
+ TemplateArgs, true);
+ }
+ }
+ }
+}
+
+/// \brief Instantiate the definitions of all of the members of the
+/// given class template specialization, which was named as part of an
+/// explicit instantiation.
+void Sema::InstantiateClassTemplateSpecializationMembers(
+ SourceLocation PointOfInstantiation,
+ ClassTemplateSpecializationDecl *ClassTemplateSpec) {
+ // C++0x [temp.explicit]p7:
+ // An explicit instantiation that names a class template
+ // specialization is an explicit instantion of the same kind
+ // (declaration or definition) of each of its members (not
+ // including members inherited from base classes) that has not
+ // been previously explicitly specialized in the translation unit
+ // containing the explicit instantiation, except as described
+ // below.
+ InstantiateClassMembers(PointOfInstantiation, ClassTemplateSpec,
+ ClassTemplateSpec->getTemplateArgs());
+}
+
/// \brief Instantiate a nested-name-specifier.
NestedNameSpecifier *
Sema::InstantiateNestedNameSpecifier(NestedNameSpecifier *NNS,
OpenPOWER on IntegriCloud