diff options
| author | Nathan James <n.james93@hotmail.co.uk> | 2020-02-26 22:06:38 +0000 |
|---|---|---|
| committer | Hans Wennborg <hans@chromium.org> | 2020-02-27 13:06:12 +0100 |
| commit | 8f2858eb07085e13544316abfd3c0e90cef3eb93 (patch) | |
| tree | aaefc0437beb5e8e62d201e3134d7f5fcbedffaa /clang/unittests | |
| parent | 058a8cd73f33ae7be7bef469c1b7c2d5fdaa4b24 (diff) | |
| download | bcm5719-llvm-8f2858eb07085e13544316abfd3c0e90cef3eb93.tar.gz bcm5719-llvm-8f2858eb07085e13544316abfd3c0e90cef3eb93.zip | |
[ASTMatchers] HasNameMatcher handles `extern "C"`
Summary: Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=42193 | hasName AST matcher is confused by extern "C" in namespace. ]]
Reviewers: klimek, aaron.ballman, gribozavr2
Reviewed By: aaron.ballman
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75202
(cherry picked from commit 16cabf278fc8c14d415e677ce0bc40d46a6de30d)
Diffstat (limited to 'clang/unittests')
| -rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp index 92678a30919..bb8aecfe8b8 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -1520,6 +1520,21 @@ TEST(Matcher, HasNameSupportsFunctionScope) { EXPECT_TRUE(matches(code, fieldDecl(hasName("::a::F(int)::S::m")))); } +TEST(Matcher, HasNameQualifiedSupportsLinkage) { + // https://bugs.llvm.org/show_bug.cgi?id=42193 + std::string code = R"cpp(namespace foo { extern "C" void test(); })cpp"; + EXPECT_TRUE(matches(code, functionDecl(hasName("test")))); + EXPECT_TRUE(matches(code, functionDecl(hasName("foo::test")))); + EXPECT_TRUE(matches(code, functionDecl(hasName("::foo::test")))); + EXPECT_TRUE(notMatches(code, functionDecl(hasName("::test")))); + + code = R"cpp(namespace foo { extern "C" { void test(); } })cpp"; + EXPECT_TRUE(matches(code, functionDecl(hasName("test")))); + EXPECT_TRUE(matches(code, functionDecl(hasName("foo::test")))); + EXPECT_TRUE(matches(code, functionDecl(hasName("::foo::test")))); + EXPECT_TRUE(notMatches(code, functionDecl(hasName("::test")))); +} + TEST(Matcher, HasAnyName) { const std::string Code = "namespace a { namespace b { class C; } }"; |

