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

Sean Callanan via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 2 17:21:28 PST 2016


Author: spyffe
Date: Wed Mar  2 19:21:28 2016
New Revision: 262572

URL: http://llvm.org/viewvc/llvm-project?rev=262572&view=rev
Log:
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>

Modified:
    cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=262572&r1=262571&r2=262572&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Mar  2 19:21:28 2016
@@ -3038,8 +3038,13 @@ Decl *ASTNodeImporter::VisitFieldDecl(Fi
                                          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);




More information about the cfe-commits mailing list