diff options
author | Balazs Keri <1.int32@gmail.com> | 2019-08-30 10:12:14 +0000 |
---|---|---|
committer | Balazs Keri <1.int32@gmail.com> | 2019-08-30 10:12:14 +0000 |
commit | b4fd7d4258589c52539043c0806fd2a143a2c15d (patch) | |
tree | 381c5c7fcafd34139954f6e7e7ea19776f07a794 /clang/unittests/AST/ASTImporterTest.cpp | |
parent | 6381b143f6cc3607a1a96442aa06dc469ea1fc79 (diff) | |
download | bcm5719-llvm-b4fd7d4258589c52539043c0806fd2a143a2c15d.tar.gz bcm5719-llvm-b4fd7d4258589c52539043c0806fd2a143a2c15d.zip |
[ASTImporter] Propagate errors during import of overridden methods.
Summary:
If importing overridden methods fails for a method it can be seen
incorrectly as non-virtual. To avoid this inconsistency the method
is marked with import error to avoid later use of it.
Reviewers: martong, a.sidorin, shafik, a_sidorin
Reviewed By: martong, shafik
Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66933
llvm-svn: 370457
Diffstat (limited to 'clang/unittests/AST/ASTImporterTest.cpp')
-rw-r--r-- | clang/unittests/AST/ASTImporterTest.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 2038e3a28a3..2c27a4417f5 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -5183,6 +5183,50 @@ TEST_P(ErrorHandlingTest, } } +TEST_P(ErrorHandlingTest, ImportOfOverriddenMethods) { + auto MatchFooA = + functionDecl(hasName("foo"), hasAncestor(cxxRecordDecl(hasName("A")))); + auto MatchFooB = + functionDecl(hasName("foo"), hasAncestor(cxxRecordDecl(hasName("B")))); + auto MatchFooC = + functionDecl(hasName("foo"), hasAncestor(cxxRecordDecl(hasName("C")))); + + // Provoke import of a method that has overridden methods with import error. + TranslationUnitDecl *FromTU = getTuDecl(std::string(R"( + struct C; + struct A { + virtual void foo(); + void f1(C *); + }; + void A::foo() { + )") + ErroneousStmt + R"( + } + struct B : public A { + void foo() override; + }; + struct C : public B { + void foo() override; + }; + )", + Lang_CXX11); + auto *FromFooA = FirstDeclMatcher<FunctionDecl>().match(FromTU, MatchFooA); + auto *FromFooB = FirstDeclMatcher<FunctionDecl>().match(FromTU, MatchFooB); + auto *FromFooC = FirstDeclMatcher<FunctionDecl>().match(FromTU, MatchFooC); + + EXPECT_FALSE(Import(FromFooA, Lang_CXX11)); + ASTImporter *Importer = findFromTU(FromFooA)->Importer.get(); + auto CheckError = [&Importer](Decl *FromD) { + Optional<ImportError> OptErr = Importer->getImportDeclErrorIfAny(FromD); + ASSERT_TRUE(OptErr); + EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct); + }; + CheckError(FromFooA); + EXPECT_FALSE(Import(FromFooB, Lang_CXX11)); + CheckError(FromFooB); + EXPECT_FALSE(Import(FromFooC, Lang_CXX11)); + CheckError(FromFooC); +} + TEST_P(ASTImporterOptionSpecificTestBase, LambdaInFunctionBody) { Decl *FromTU = getTuDecl( R"( |