diff options
author | Balazs Keri <1.int32@gmail.com> | 2018-08-08 09:40:57 +0000 |
---|---|---|
committer | Balazs Keri <1.int32@gmail.com> | 2018-08-08 09:40:57 +0000 |
commit | 2544b4b00ac05cf2e80cd4c7a75277dd930ec80d (patch) | |
tree | 293582c97c10b3a24c6221b40d02457f0870f77f /clang/unittests/AST/ASTImporterTest.cpp | |
parent | 4107b31df25af1d5ff65607e83686ec4188b7349 (diff) | |
download | bcm5719-llvm-2544b4b00ac05cf2e80cd4c7a75277dd930ec80d.tar.gz bcm5719-llvm-2544b4b00ac05cf2e80cd4c7a75277dd930ec80d.zip |
[ASTImporter] Load external Decls when getting field index.
Summary:
At equality check of fields without name the index of fields is compared.
At determining the index of a field all fields of the parent context
should be loaded from external source to find the field at all.
Reviewers: a.sidorin, a_sidorin, r.stahl
Reviewed By: a.sidorin
Subscribers: martong, cfe-commits
Differential Revision: https://reviews.llvm.org/D49796
llvm-svn: 339226
Diffstat (limited to 'clang/unittests/AST/ASTImporterTest.cpp')
-rw-r--r-- | clang/unittests/AST/ASTImporterTest.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 04006a0bea3..2690f4e5f1f 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -2641,6 +2641,40 @@ TEST_P(ASTImporterTestBase, ImportUnnamedStructsWithRecursingField) { R1, recordDecl(has(fieldDecl(hasName("next")))))); } +TEST_P(ASTImporterTestBase, ImportUnnamedFieldsInCorrectOrder) { + Decl *FromTU = getTuDecl( + R"( + void f(int X, int Y, bool Z) { + (void)[X, Y, Z] { (void)Z; }; + } + )", + Lang_CXX11, "input0.cc"); + auto *FromF = FirstDeclMatcher<FunctionDecl>().match( + FromTU, functionDecl(hasName("f"))); + auto *ToF = cast_or_null<FunctionDecl>(Import(FromF, Lang_CXX11)); + EXPECT_TRUE(ToF); + + CXXRecordDecl *FromLambda = + cast<LambdaExpr>(cast<CStyleCastExpr>(cast<CompoundStmt>( + FromF->getBody())->body_front())->getSubExpr())->getLambdaClass(); + + auto *ToLambda = cast_or_null<CXXRecordDecl>(Import(FromLambda, Lang_CXX11)); + EXPECT_TRUE(ToLambda); + + // Check if the fields of the lambda class are imported in correct order. + unsigned FromIndex = 0u; + for (auto *FromField : FromLambda->fields()) { + ASSERT_FALSE(FromField->getDeclName()); + auto *ToField = cast_or_null<FieldDecl>(Import(FromField, Lang_CXX11)); + EXPECT_TRUE(ToField); + unsigned ToIndex = ASTImporter::getFieldIndex(ToField); + EXPECT_EQ(ToIndex, FromIndex + 1); + ++FromIndex; + } + + EXPECT_EQ(FromIndex, 3u); +} + struct DeclContextTest : ASTImporterTestBase {}; TEST_P(DeclContextTest, removeDeclOfClassTemplateSpecialization) { |