Skip to content

Commit

Permalink
[ASTImporter] Add new tests about templated-described swing
Browse files Browse the repository at this point in the history
Summary:
Add a new test about importing a partial specialization (of a class).  Also,
this patch adds new tests about the templated-described swing, some of these
fail ATM, but subsequent patches will fix them.

Reviewers: a.sidorin, r.stahl, xazax.hun

Subscribers: rnkovacs, dkrupp, cfe-commits

Differential Revision: https://reviews.llvm.org/D47534

llvm-svn: 335455
  • Loading branch information
martong committed Jun 25, 2018
1 parent 3a0e13f commit 6578a4a
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions clang/unittests/AST/ASTImporterTest.cpp
Expand Up @@ -1095,6 +1095,20 @@ TEST(ImportDecl, ImportTemplatedDeclForTemplate) {
unless(has(cxxRecordDecl(hasName("declToImport"))))))));
}

TEST(ImportDecl, ImportClassTemplatePartialSpecialization) {
MatchVerifier<Decl> Verifier;
auto Code =
R"s(
struct declToImport {
template <typename T0> struct X;
template <typename T0> struct X<T0 *> {};
};
)s";
testImport(Code, Lang_CXX, "", Lang_CXX, Verifier,
recordDecl(has(classTemplateDecl()),
has(classTemplateSpecializationDecl())));
}

TEST(ImportExpr, CXXOperatorCallExpr) {
MatchVerifier<Decl> Verifier;
testImport("class declToImport {"
Expand Down Expand Up @@ -1128,6 +1142,52 @@ TEST_P(ASTImporterTestBase, ImportOfTemplatedDeclOfClassTemplateDecl) {
EXPECT_EQ(ToTemplated1, ToTemplated);
}

TEST_P(ASTImporterTestBase,
DISABLED_ImportOfTemplatedDeclOfFunctionTemplateDecl) {
Decl *FromTU = getTuDecl("template<class X> void f(){}", Lang_CXX);
auto From = FirstDeclMatcher<FunctionTemplateDecl>().match(
FromTU, functionTemplateDecl());
ASSERT_TRUE(From);
auto To = cast<FunctionTemplateDecl>(Import(From, Lang_CXX));
ASSERT_TRUE(To);
Decl *ToTemplated = To->getTemplatedDecl();
Decl *ToTemplated1 = Import(From->getTemplatedDecl(), Lang_CXX);
EXPECT_TRUE(ToTemplated1);
EXPECT_EQ(ToTemplated1, ToTemplated);
}

TEST_P(ASTImporterTestBase,
ImportOfTemplatedDeclShouldImportTheClassTemplateDecl) {
Decl *FromTU = getTuDecl("template<class X> struct S{};", Lang_CXX);
auto FromFT =
FirstDeclMatcher<ClassTemplateDecl>().match(FromTU, classTemplateDecl());
ASSERT_TRUE(FromFT);

auto ToTemplated =
cast<CXXRecordDecl>(Import(FromFT->getTemplatedDecl(), Lang_CXX));
EXPECT_TRUE(ToTemplated);
auto ToTU = ToTemplated->getTranslationUnitDecl();
auto ToFT =
FirstDeclMatcher<ClassTemplateDecl>().match(ToTU, classTemplateDecl());
EXPECT_TRUE(ToFT);
}

TEST_P(ASTImporterTestBase,
DISABLED_ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) {
Decl *FromTU = getTuDecl("template<class X> void f(){}", Lang_CXX);
auto FromFT = FirstDeclMatcher<FunctionTemplateDecl>().match(
FromTU, functionTemplateDecl());
ASSERT_TRUE(FromFT);

auto ToTemplated =
cast<FunctionDecl>(Import(FromFT->getTemplatedDecl(), Lang_CXX));
EXPECT_TRUE(ToTemplated);
auto ToTU = ToTemplated->getTranslationUnitDecl();
auto ToFT = FirstDeclMatcher<FunctionTemplateDecl>().match(
ToTU, functionTemplateDecl());
EXPECT_TRUE(ToFT);
}

TEST_P(ASTImporterTestBase, ImportCorrectTemplatedDecl) {
auto Code =
R"(
Expand Down

0 comments on commit 6578a4a

Please sign in to comment.