Fixed a problem where the ASTImporter mishandled in-class initializers.

Previously, the ASTImporter, when copying a FieldDecl, would make the
new FieldDecl use the exact same in-class initializer as the original
FieldDecl, which is a problem since the initializer is in the wrong AST.
The initializer must be imported, just like all the other parts of the
field.

Doug Gregor reviewed this fix.

<rdar://problem/24943405>

llvm-svn: 262572
This commit is contained in:
Sean Callanan 2016-03-03 01:21:28 +00:00
parent ae27b2380f
commit bb33f58a1a
1 changed files with 7 additions and 2 deletions

View File

@ -3038,8 +3038,13 @@ Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) {
D->getInClassInitStyle());
ToField->setAccess(D->getAccess());
ToField->setLexicalDeclContext(LexicalDC);
if (ToField->hasInClassInitializer())
ToField->setInClassInitializer(D->getInClassInitializer());
if (Expr *FromInitializer = ToField->getInClassInitializer()) {
Expr *ToInitializer = Importer.Import(FromInitializer);
if (ToInitializer)
ToField->setInClassInitializer(ToInitializer);
else
return nullptr;
}
ToField->setImplicit(D->isImplicit());
Importer.Imported(D, ToField);
LexicalDC->addDeclInternal(ToField);