The init expression of a VarDecl is overwritten in the "To" context if we import a VarDecl without an init expression (and with a definition).
The following unittest fails:
TEST_P(ASTImporterTestBase,
Maci) {
auto StructA =
R"(
struct A {
static const int a = 1 + 2;
};
)";
Decl *ToTU = getToTuDecl(StructA, Lang_CXX);
Decl *FromTU =
getTuDecl(std::string(StructA) + "const int A::a;", Lang_CXX, "input1.cc");
auto *FromD0 = FirstDeclMatcher<VarDecl>().match(FromTU, varDecl(hasName("a"))); // Decl with init
auto *FromD1 = LastDeclMatcher<VarDecl>().match(FromTU, varDecl(hasName("a"))); // Decl with definition
ASSERT_EQ(FromD0, FromD1->getPreviousDecl());
ASSERT_TRUE(FromD0->getInit());
ASSERT_FALSE(FromD0->isThisDeclarationADefinition());
ASSERT_TRUE(FromD1->isThisDeclarationADefinition());
ASSERT_FALSE(FromD1->getInit());
auto *ToD = FirstDeclMatcher<VarDecl>().match(ToTU, varDecl(hasName("a"))); // Decl with init
ASSERT_TRUE(ToD->getInit());
ASSERT_FALSE(ToD->getDefinition());
auto *ImportedD = cast<VarDecl>(Import(FromD1, Lang_CXX11));
EXPECT_TRUE(ImportedD->getAnyInitializer());
EXPECT_TRUE(ImportedD->getDefinition());
//EXPECT_TRUE(false);
}
The init expression of a VarDecl is overwritten in the "To" context if we import a VarDecl without an init expression (and with a definition). The following unittest fails: