summaryrefslogtreecommitdiffstats
path: root/clang/unittests/AST/ASTImporterTest.cpp
diff options
context:
space:
mode:
authorAleksei Sidorin <a.sidorin@samsung.com>2018-01-26 11:36:54 +0000
committerAleksei Sidorin <a.sidorin@samsung.com>2018-01-26 11:36:54 +0000
commit8fc8510cb8dab5857e62870e976dfa7feca3fca7 (patch)
tree987fca5b298b2c15fa7be4579f9ea381df60058b /clang/unittests/AST/ASTImporterTest.cpp
parent24f0fa34c2e8d01ce97008f0f664016378079a92 (diff)
downloadbcm5719-llvm-8fc8510cb8dab5857e62870e976dfa7feca3fca7.tar.gz
bcm5719-llvm-8fc8510cb8dab5857e62870e976dfa7feca3fca7.zip
[ASTImporter] Support LambdaExprs and improve template support
Also, a number of style and bug fixes was done: * ASTImporterTest: added sanity check for source node * ExternalASTMerger: better lookup for template specializations * ASTImporter: don't add templated declarations into DeclContext * ASTImporter: introduce a helper, ImportTemplateArgumentListInfo getting SourceLocations * ASTImporter: proper set ParmVarDecls for imported FunctionProtoTypeLoc Differential Revision: https://reviews.llvm.org/D42301 llvm-svn: 323519
Diffstat (limited to 'clang/unittests/AST/ASTImporterTest.cpp')
-rw-r--r--clang/unittests/AST/ASTImporterTest.cpp35
1 files changed, 28 insertions, 7 deletions
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 5b87876989a..277d16fa3b3 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -11,9 +11,9 @@
//
//===----------------------------------------------------------------------===//
+#include "MatchVerifier.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTImporter.h"
-#include "MatchVerifier.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Tooling/Tooling.h"
@@ -99,7 +99,11 @@ testImport(const std::string &FromCode, const ArgVector &FromArgs,
if (FoundDecls.size() != 1)
return testing::AssertionFailure() << "Multiple declarations were found!";
- auto Imported = Importer.Import(*FoundDecls.begin());
+ // Sanity check: the node being imported should match in the same way as
+ // the result node.
+ EXPECT_TRUE(Verifier.match(FoundDecls.front(), AMatcher));
+
+ auto Imported = Importer.Import(FoundDecls.front());
if (!Imported)
return testing::AssertionFailure() << "Import failed, nullptr returned!";
@@ -624,7 +628,7 @@ TEST(ImportExpr, ImportCXXPseudoDestructorExpr) {
TEST(ImportDecl, ImportUsingDecl) {
MatchVerifier<Decl> Verifier;
testImport("namespace foo { int bar; }"
- "int declToImport(){ using foo::bar; }",
+ "void declToImport() { using foo::bar; }",
Lang_CXX, "", Lang_CXX, Verifier,
functionDecl(
has(
@@ -665,13 +669,13 @@ TEST(ImportExpr, ImportUnresolvedLookupExpr) {
"}"
"void instantiate() { declToImport<int>(); }",
Lang_CXX, "", Lang_CXX, Verifier,
- functionTemplateDecl(has(functionDecl(has(
- compoundStmt(has(unresolvedLookupExpr())))))));
+ functionTemplateDecl(has(functionDecl(
+ has(compoundStmt(has(unresolvedLookupExpr())))))));
}
TEST(ImportExpr, ImportCXXUnresolvedConstructExpr) {
MatchVerifier<Decl> Verifier;
- testImport("template <typename T> class C { T t; };"
+ testImport("template <typename T> struct C { T t; };"
"template <typename T> void declToImport() {"
" C<T> d;"
" d.t = T();"
@@ -680,7 +684,7 @@ TEST(ImportExpr, ImportCXXUnresolvedConstructExpr) {
Lang_CXX, "", Lang_CXX, Verifier,
functionTemplateDecl(has(functionDecl(has(compoundStmt(has(
binaryOperator(has(cxxUnresolvedConstructExpr())))))))));
- testImport("template <typename T> class C { T t; };"
+ testImport("template <typename T> struct C { T t; };"
"template <typename T> void declToImport() {"
" C<T> d;"
" (&d)->t = T();"
@@ -691,5 +695,22 @@ TEST(ImportExpr, ImportCXXUnresolvedConstructExpr) {
binaryOperator(has(cxxUnresolvedConstructExpr())))))))));
}
+/// Check that function "declToImport()" (which is the templated function
+/// for corresponding FunctionTemplateDecl) is not added into DeclContext.
+/// Same for class template declarations.
+TEST(ImportDecl, ImportTemplatedDeclForTemplate) {
+ MatchVerifier<Decl> Verifier;
+ testImport("template <typename T> void declToImport() { T a = 1; }"
+ "void instantiate() { declToImport<int>(); }",
+ Lang_CXX, "", Lang_CXX, Verifier,
+ functionTemplateDecl(hasAncestor(translationUnitDecl(
+ unless(has(functionDecl(hasName("declToImport"))))))));
+ testImport("template <typename T> struct declToImport { T t; };"
+ "void instantiate() { declToImport<int>(); }",
+ Lang_CXX, "", Lang_CXX, Verifier,
+ classTemplateDecl(hasAncestor(translationUnitDecl(
+ unless(has(cxxRecordDecl(hasName("declToImport"))))))));
+}
+
} // end namespace ast_matchers
} // end namespace clang
OpenPOWER on IntegriCloud