diff options
Diffstat (limited to 'clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp')
| -rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp index fcd3dcb5af0..ff45fe6c510 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -641,6 +641,89 @@ TEST(TemplateArgument, Matches) { functionDecl(hasAnyTemplateArgument(templateArgument())))); } +TEST(TemplateTypeParmDecl, CXXMethodDecl) { + const char input[] = + "template<typename T>\n" + "class Class {\n" + " void method();\n" + "};\n" + "template<typename U>\n" + "void Class<U>::method() {}\n"; + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("T")))); + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("U")))); +} + +TEST(TemplateTypeParmDecl, VarDecl) { + const char input[] = + "template<typename T>\n" + "class Class {\n" + " static T pi;\n" + "};\n" + "template<typename U>\n" + "U Class<U>::pi = U(3.1415926535897932385);\n"; + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("T")))); + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("U")))); +} + +TEST(TemplateTypeParmDecl, VarTemplatePartialSpecializationDecl) { + const char input[] = + "template<typename T>\n" + "struct Struct {\n" + " template<typename T2> static int field;\n" + "};\n" + "template<typename U>\n" + "template<typename U2>\n" + "int Struct<U>::field<char> = 123;\n"; + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("T")))); + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("T2")))); + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("U")))); + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("U2")))); +} + +TEST(TemplateTypeParmDecl, ClassTemplatePartialSpecializationDecl) { + const char input[] = + "template<typename T>\n" + "class Class {\n" + " template<typename T2> struct Struct;\n" + "};\n" + "template<typename U>\n" + "template<typename U2>\n" + "struct Class<U>::Struct<int> {};\n"; + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("T")))); + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("T2")))); + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("U")))); + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("U2")))); +} + +TEST(TemplateTypeParmDecl, EnumDecl) { + const char input[] = + "template<typename T>\n" + "struct Struct {\n" + " enum class Enum : T;\n" + "};\n" + "template<typename U>\n" + "enum class Struct<U>::Enum : U {\n" + " e1,\n" + " e2\n" + "};\n"; + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("T")))); + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("U")))); +} + +TEST(TemplateTypeParmDecl, RecordDecl) { + const char input[] = + "template<typename T>\n" + "class Class {\n" + " struct Struct;\n" + "};\n" + "template<typename U>\n" + "struct Class<U>::Struct {\n" + " U field;\n" + "};\n"; + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("T")))); + EXPECT_TRUE(matches(input, templateTypeParmDecl(hasName("U")))); +} + TEST(RefersToIntegralType, Matches) { EXPECT_TRUE(matches("template<int T> struct C {}; C<42> c;", classTemplateSpecializationDecl( |

