mirror of https://github.com/microsoft/clang.git
[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
This commit is contained in:
parent
a8fca7b41c
commit
109df809f0
|
@ -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<CXXRecordDecl>(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 =
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
template <class X>
|
||||
class C { static X x; };
|
|
@ -0,0 +1,2 @@
|
|||
template <class X>
|
||||
X C<X>::x;
|
|
@ -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
|
Loading…
Reference in New Issue