[PATCH] D47534: [ASTImporter] Add new tests about templated-described swing

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 25 04:41:34 PDT 2018


martong updated this revision to Diff 152660.
martong marked 2 inline comments as done.
martong added a comment.

- Clang format the test code snippet.


Repository:
  rC Clang

https://reviews.llvm.org/D47534

Files:
  unittests/AST/ASTImporterTest.cpp


Index: unittests/AST/ASTImporterTest.cpp
===================================================================
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -1095,6 +1095,20 @@
                  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 @@
   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"(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47534.152660.patch
Type: text/x-patch
Size: 2767 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180625/d7e9eb78/attachment-0001.bin>


More information about the cfe-commits mailing list