diff options
author | Samuel Benzaquen <sbenza@google.com> | 2016-02-05 18:29:24 +0000 |
---|---|---|
committer | Samuel Benzaquen <sbenza@google.com> | 2016-02-05 18:29:24 +0000 |
commit | c1abc952dc13cf141bdc0129debbf409f6dc9ece (patch) | |
tree | 24705af2d56222e699a943682a3203d8c76222e7 /unittests | |
parent | 508fd615f6d875d09332a57a9b9f085f724c41b8 (diff) | |
download | clang-c1abc952dc13cf141bdc0129debbf409f6dc9ece.tar.gz |
[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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259898 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 38582c8870..2aaa92c35b 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/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()); |