Author: martong Date: Mon Jun 25 04:38:43 2018 New Revision: 335455 URL: http://llvm.org/viewvc/llvm-project?rev=335455&view=rev Log: [ASTImporter] Add new tests about templated-described swing
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 Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=335455&r1=335454&r2=335455&view=diff ============================================================================== --- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original) +++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Mon Jun 25 04:38:43 2018 @@ -1095,6 +1095,20 @@ TEST(ImportDecl, ImportTemplatedDeclForT 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 {" @@ -1128,6 +1142,52 @@ TEST_P(ASTImporterTestBase, ImportOfTemp 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"( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits