[ASTImporter] Added error handling for AST import.
Summary:
The goal of this change is to make the ASTImporter::Import functions return
llvm::Expected instead of the imported type.
As first part the ASTNodeImporter visit functions are updated to return with
llvm::Expected. Various `import` functions are added to ASTNodeImporter to
simplify the code and have a common place for interface towards ASTImporter
(from ASTNodeImporter). There is some temporary code that is needed before
ASTImporter is updated.
Reviewers: a.sidorin, a_sidorin, xazax.hun
Reviewed By: a_sidorin
Subscribers: dkrupp, Szelethus, rnkovacs, martong, jfb, cfe-commits
Differential Revision: https://reviews.llvm.org/D51633
llvm-svn: 344783
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index ecfdeb0..d1683cd 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -2922,8 +2922,9 @@
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);
+ Optional<unsigned> ToIndex = ASTImporter::getFieldIndex(ToField);
+ EXPECT_TRUE(ToIndex);
+ EXPECT_EQ(*ToIndex, FromIndex);
++FromIndex;
}