diff options
| author | Hans Wennborg <hans@hanshq.net> | 2016-05-26 19:42:56 +0000 |
|---|---|---|
| committer | Hans Wennborg <hans@hanshq.net> | 2016-05-26 19:42:56 +0000 |
| commit | a86a83bb2e49aa51cea215ab7cefd6ee24e636ea (patch) | |
| tree | 8f7691df29f88a6ea795418c3bf03521634ba134 /clang/lib/Sema | |
| parent | 14aa2ad1f466d54e275ba9f1327e79ef7c8c52ce (diff) | |
| download | bcm5719-llvm-a86a83bb2e49aa51cea215ab7cefd6ee24e636ea.tar.gz bcm5719-llvm-a86a83bb2e49aa51cea215ab7cefd6ee24e636ea.zip | |
Re-commit r270748 "clang-cl: Treat dllimport explicit template instantiation definitions as declarations (PR27810, PR27811)"
Also make explicit instantiation decls not apply to nested classes when
targeting MSVC. That dll attributes are not inherited by inner classes
might be the explanation for MSVC's behaviour here.
llvm-svn: 270897
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 33 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiate.cpp | 7 |
2 files changed, 38 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 59e984dd93e..73b5c44b599 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -7367,6 +7367,29 @@ Sema::ActOnExplicitInstantiation(Scope *S, } } + // In MSVC mode, dllimported explicit instantiation definitions are treated as + // instantiation declarations for most purposes. + bool DLLImportExplicitInstantiationDef = false; + if (TSK == TSK_ExplicitInstantiationDefinition && + Context.getTargetInfo().getCXXABI().isMicrosoft()) { + // Check for dllimport class template instantiation definitions. + bool DLLImport = + ClassTemplate->getTemplatedDecl()->getAttr<DLLImportAttr>(); + for (AttributeList *A = Attr; A; A = A->getNext()) { + if (A->getKind() == AttributeList::AT_DLLImport) + DLLImport = true; + if (A->getKind() == AttributeList::AT_DLLExport) { + // dllexport trumps dllimport here. + DLLImport = false; + break; + } + } + if (DLLImport) { + TSK = TSK_ExplicitInstantiationDeclaration; + DLLImportExplicitInstantiationDef = true; + } + } + // Translate the parser's template argument list in our AST format. TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc); translateTemplateArguments(TemplateArgsIn, TemplateArgs); @@ -7420,6 +7443,12 @@ Sema::ActOnExplicitInstantiation(Scope *S, Specialization->setLocation(TemplateNameLoc); PrevDecl = nullptr; } + + if (PrevDecl_TSK == TSK_ExplicitInstantiationDeclaration && + DLLImportExplicitInstantiationDef) { + // The new specialization might add a dllimport attribute. + HasNoEffect = false; + } } if (!Specialization) { @@ -7497,11 +7526,11 @@ Sema::ActOnExplicitInstantiation(Scope *S, Specialization->getDefinition()); if (Def) { TemplateSpecializationKind Old_TSK = Def->getTemplateSpecializationKind(); - // Fix a TSK_ExplicitInstantiationDeclaration followed by a // TSK_ExplicitInstantiationDefinition if (Old_TSK == TSK_ExplicitInstantiationDeclaration && - TSK == TSK_ExplicitInstantiationDefinition) { + (TSK == TSK_ExplicitInstantiationDefinition || + DLLImportExplicitInstantiationDef)) { // FIXME: Need to notify the ASTMutationListener that we did this. Def->setTemplateSpecializationKind(TSK); diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 243fedbd65b..39ea31656a1 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2542,6 +2542,13 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, == TSK_ExplicitSpecialization) continue; + if (Context.getTargetInfo().getCXXABI().isMicrosoft() && + TSK == TSK_ExplicitInstantiationDeclaration) { + // In MSVC mode, explicit instantiation decl of the outer class doesn't + // affect the inner class. + continue; + } + if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, Record, MSInfo->getTemplateSpecializationKind(), |

