summaryrefslogtreecommitdiffstats
path: root/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
diff options
context:
space:
mode:
authorSamuel Benzaquen <sbenza@google.com>2016-02-05 18:29:24 +0000
committerSamuel Benzaquen <sbenza@google.com>2016-02-05 18:29:24 +0000
commit8e566f37409736e76ad3aa515975014d8ee5ca9d (patch)
tree4381c918c60913a0ad23a2cbd03d8da05f4134bc /clang/unittests/ASTMatchers/ASTMatchersTest.cpp
parent5dde1d2eb35ab6f2cd2386d6be016782a522f88b (diff)
downloadbcm5719-llvm-8e566f37409736e76ad3aa515975014d8ee5ca9d.tar.gz
bcm5719-llvm-8e566f37409736e76ad3aa515975014d8ee5ca9d.zip
[ASTMatchers] Allow hasName() to look through inline namespaces
Summary: Allow hasName() to look through inline namespaces. This will fix the interaction between some clang-tidy checks and libc++. libc++ defines names in an inline namespace named std::<version_#>. When we try to match a name using hasName("std::xxx") it fails to match and the clang-tidy check does not work. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D15506 llvm-svn: 259898
Diffstat (limited to 'clang/unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersTest.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
index 38582c88701..2aaa92c35b8 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -2827,6 +2827,52 @@ TEST(Matcher, HasNameSupportsOuterClasses) {
recordDecl(hasName("A+B::C"))));
}
+TEST(Matcher, HasNameSupportsInlinedNamespaces) {
+ std::string code = "namespace a { inline namespace b { class C; } }";
+ EXPECT_TRUE(matches(code, recordDecl(hasName("a::b::C"))));
+ EXPECT_TRUE(matches(code, recordDecl(hasName("a::C"))));
+ EXPECT_TRUE(matches(code, recordDecl(hasName("::a::b::C"))));
+ EXPECT_TRUE(matches(code, recordDecl(hasName("::a::C"))));
+}
+
+TEST(Matcher, HasNameSupportsAnonymousNamespaces) {
+ std::string code = "namespace a { namespace { class C; } }";
+ EXPECT_TRUE(
+ matches(code, recordDecl(hasName("a::(anonymous namespace)::C"))));
+ EXPECT_TRUE(matches(code, recordDecl(hasName("a::C"))));
+ EXPECT_TRUE(
+ matches(code, recordDecl(hasName("::a::(anonymous namespace)::C"))));
+ EXPECT_TRUE(matches(code, recordDecl(hasName("::a::C"))));
+}
+
+TEST(Matcher, HasNameSupportsAnonymousOuterClasses) {
+ EXPECT_TRUE(matches("class A { class { class C; } x; };",
+ recordDecl(hasName("A::(anonymous class)::C"))));
+ EXPECT_TRUE(matches("class A { class { class C; } x; };",
+ recordDecl(hasName("::A::(anonymous class)::C"))));
+ EXPECT_FALSE(matches("class A { class { class C; } x; };",
+ recordDecl(hasName("::A::C"))));
+ EXPECT_TRUE(matches("class A { struct { class C; } x; };",
+ recordDecl(hasName("A::(anonymous struct)::C"))));
+ EXPECT_TRUE(matches("class A { struct { class C; } x; };",
+ recordDecl(hasName("::A::(anonymous struct)::C"))));
+ EXPECT_FALSE(matches("class A { struct { class C; } x; };",
+ recordDecl(hasName("::A::C"))));
+}
+
+TEST(Matcher, HasNameSupportsFunctionScope) {
+ std::string code =
+ "namespace a { void F(int a) { struct S { int m; }; int i; } }";
+ EXPECT_TRUE(matches(code, varDecl(hasName("i"))));
+ EXPECT_FALSE(matches(code, varDecl(hasName("F()::i"))));
+
+ EXPECT_TRUE(matches(code, fieldDecl(hasName("m"))));
+ EXPECT_TRUE(matches(code, fieldDecl(hasName("S::m"))));
+ EXPECT_TRUE(matches(code, fieldDecl(hasName("F(int)::S::m"))));
+ EXPECT_TRUE(matches(code, fieldDecl(hasName("a::F(int)::S::m"))));
+ EXPECT_TRUE(matches(code, fieldDecl(hasName("::a::F(int)::S::m"))));
+}
+
TEST(Matcher, IsDefinition) {
DeclarationMatcher DefinitionOfClassA =
recordDecl(hasName("A"), isDefinition());
OpenPOWER on IntegriCloud