From 2b2e7a1c3d62dd98ed8a274e7f91818c329539d4 Mon Sep 17 00:00:00 2001 From: Sean Callanan Date: Thu, 3 Mar 2016 01:21:28 +0000 Subject: [PATCH] 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 --- lib/AST/ASTImporter.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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); -- 2.50.1