Skip to content

Commit

Permalink
Handle injected class names in the ASTImporter.
Browse files Browse the repository at this point in the history
Every class as parsed by Clang has a forward declaration of itself as a member:

class A {
  class A;
  ...
}

but when the parser generates this it ensures that the RecordTypes for the two 
are the same.  This makes (among other things) inheritance work.  This patch
fixes a bug where the ASTImporter generated two separate RecordTypes when
importing the class and the contained forward declaration, and adds a test case.

Thanks to Doug Gregor for advice on this.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@269551 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
scallanan committed May 14, 2016
1 parent 9b9908a commit d944e0e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2820,8 +2820,17 @@ Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl());
if (DCXX->getLambdaContextDecl() && !CDecl)
return nullptr;
D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(),
CDecl);
D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl);
} else if (DCXX->isInjectedClassName()) {
// We have to be careful to do a similar dance to the one in
// Sema::ActOnStartCXXMemberDeclarations
CXXRecordDecl *const PrevDecl = nullptr;
const bool DelayTypeCreation = true;
D2CXX = CXXRecordDecl::Create(
Importer.getToContext(), D->getTagKind(), DC, StartLoc, Loc,
Name.getAsIdentifierInfo(), PrevDecl, DelayTypeCreation);
Importer.getToContext().getTypeDeclType(
D2CXX, llvm::dyn_cast<CXXRecordDecl>(DC));
} else {
D2CXX = CXXRecordDecl::Create(Importer.getToContext(),
D->getTagKind(),
Expand Down
7 changes: 7 additions & 0 deletions test/ASTMerge/Inputs/inheritance-base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class A
{
public:
int x;
A(int _x) : x(_x) {
}
};
8 changes: 8 additions & 0 deletions test/ASTMerge/inheritance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z -emit-pch -o %t.1.ast %S/Inputs/inheritance-base.cpp
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z -ast-merge %t.1.ast -fsyntax-only -verify %s
// expected-no-diagnostics

class B : public A {
B(int _a) : A(_a) {
}
};

0 comments on commit d944e0e

Please sign in to comment.