From: Gabor Marton Date: Tue, 26 Jun 2018 13:44:24 +0000 (+0000) Subject: [ASTImporter] Use InjectedClassNameType at import of templated record. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=109df809f086d717e89b81cad4458f7055e8f10b;p=clang [ASTImporter] Use InjectedClassNameType at import of templated record. Summary: At import of a record describing a template set its type to InjectedClassNameType (instead of RecordType). Reviewers: a.sidorin, martong, r.stahl Reviewed By: a.sidorin, martong, r.stahl Subscribers: a_sidorin, rnkovacs, martong, cfe-commits Differential Revision: https://reviews.llvm.org/D47450 Patch by Balazs Keri! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335600 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index f812244ed3..6f14ab02ea 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -2135,6 +2135,29 @@ Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { if (!ToDescribed) return nullptr; D2CXX->setDescribedClassTemplate(ToDescribed); + if (!DCXX->isInjectedClassName()) { + // In a record describing a template the type should be an + // InjectedClassNameType (see Sema::CheckClassTemplate). Update the + // previously set type to the correct value here (ToDescribed is not + // available at record create). + // FIXME: The previous type is cleared but not removed from + // ASTContext's internal storage. + CXXRecordDecl *Injected = nullptr; + for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { + auto *Record = dyn_cast(Found); + if (Record && Record->isInjectedClassName()) { + Injected = Record; + break; + } + } + D2CXX->setTypeForDecl(nullptr); + Importer.getToContext().getInjectedClassNameType(D2CXX, + ToDescribed->getInjectedClassNameSpecialization()); + if (Injected) { + Injected->setTypeForDecl(nullptr); + Importer.getToContext().getTypeDeclType(Injected, D2CXX); + } + } } else if (MemberSpecializationInfo *MemberInfo = DCXX->getMemberSpecializationInfo()) { TemplateSpecializationKind SK = diff --git a/test/ASTMerge/injected-class-name-decl/Inputs/inject1.cpp b/test/ASTMerge/injected-class-name-decl/Inputs/inject1.cpp new file mode 100644 index 0000000000..f6f769746d --- /dev/null +++ b/test/ASTMerge/injected-class-name-decl/Inputs/inject1.cpp @@ -0,0 +1,2 @@ +template +class C { static X x; }; diff --git a/test/ASTMerge/injected-class-name-decl/Inputs/inject2.cpp b/test/ASTMerge/injected-class-name-decl/Inputs/inject2.cpp new file mode 100644 index 0000000000..7cf5fc2232 --- /dev/null +++ b/test/ASTMerge/injected-class-name-decl/Inputs/inject2.cpp @@ -0,0 +1,2 @@ +template +X C::x; diff --git a/test/ASTMerge/injected-class-name-decl/test.cpp b/test/ASTMerge/injected-class-name-decl/test.cpp new file mode 100644 index 0000000000..9f31674108 --- /dev/null +++ b/test/ASTMerge/injected-class-name-decl/test.cpp @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -std=c++1z -emit-pch -o %t.ast %S/Inputs/inject1.cpp +// RUN: %clang_cc1 -std=c++1z -emit-obj -o /dev/null -ast-merge %t.ast %S/Inputs/inject2.cpp +// expected-no-diagnostics