[PATCH] D23585: [ASTMatchers] Add narrowing matcher: hasExternalFormalLinkage
Visoiu Mistrih Francis via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 16 17:03:37 PDT 2016
thegameg updated this revision to Diff 68288.
thegameg added a comment.
Mention UniqueExternalLinkage type, add a test according to it.
`EXPECT_FALSE(matches(` -> `EXPECT_TRUE(notMatches(`
https://reviews.llvm.org/D23585
Files:
include/clang/ASTMatchers/ASTMatchers.h
unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1939,12 +1939,18 @@
TEST(HasExternalFormalLinkage, Basic) {
EXPECT_TRUE(matches("int a = 0;", namedDecl(hasExternalFormalLinkage())));
- EXPECT_FALSE(
- matches("static int a = 0;", namedDecl(hasExternalFormalLinkage())));
- EXPECT_FALSE(matches("static void f(void) { int a = 0; }",
- namedDecl(hasExternalFormalLinkage())));
+ EXPECT_TRUE(
+ notMatches("static int a = 0;", namedDecl(hasExternalFormalLinkage())));
+ EXPECT_TRUE(notMatches("static void f(void) { int a = 0; }",
+ namedDecl(hasExternalFormalLinkage())));
EXPECT_TRUE(matches("void f(void) { int a = 0; }",
namedDecl(hasExternalFormalLinkage())));
+
+ // Despite having internal semantic linkage, the anonymous namespace member
+ // has external linkage because the member has a unique name in all
+ // translation units.
+ EXPECT_TRUE(matches("namespace { int a = 0; }",
+ namedDecl(hasExternalFormalLinkage())));
}
} // namespace ast_matchers
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -5486,6 +5486,22 @@
/// }
/// int z;
/// \endcode
+///
+/// From clang/Basic/Linkage.h:
+/// > UniqueExternalLinkage:
+/// > External linkage within a unique namespace.
+/// > From the language perspective, these entities have external
+/// > linkage. However, since they reside in an anonymous namespace,
+/// > their names are unique to this translation unit, which is
+/// > equivalent to having internal linkage from the code-generation
+/// > point of view.
+///
+/// Example matches f (matcher = functionDecl(hasExternalFormalLinkage()))
+/// \code
+/// namespace {
+/// void f() {}
+/// }
+/// \endcode
AST_MATCHER(NamedDecl, hasExternalFormalLinkage) {
return Node.hasExternalFormalLinkage();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23585.68288.patch
Type: text/x-patch
Size: 2190 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160817/f46cea7f/attachment.bin>
More information about the cfe-commits
mailing list