From: Sean Callanan Date: Thu, 3 Mar 2016 01:21:28 +0000 (+0000) Subject: Fixed a problem where the ASTImporter mishandled in-class initializers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2b2e7a1c3d62dd98ed8a274e7f91818c329539d4;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262572 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index d6b9424fb4..a21a7e56fc 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -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);