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>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262572
91177308-0d34-0410-b5e6-
96231b3b80d8
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);