summaryrefslogtreecommitdiffstats
path: root/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
diff options
context:
space:
mode:
authorMalcolm Parsons <malcolm.parsons@gmail.com>2016-12-24 13:35:14 +0000
committerMalcolm Parsons <malcolm.parsons@gmail.com>2016-12-24 13:35:14 +0000
commit8614176ac530460aaaa4e9f593fa173f12cb760d (patch)
tree321a9a16ef9c059103551ce1272466dca16a0c95 /unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
parent1083e52e5a3e3c5d410816ba75077f49e96dfe1c (diff)
[ASTMatchers] Add hasInClassInitializer traversal matcher for FieldDecl.
Summary: I needed to know whether a FieldDecl had an in-class initializer for D26453. I used a narrowing matcher there, but a traversal matcher might be generally useful. Reviewers: sbenza, bkramer, klimek, aaron.ballman Subscribers: aaron.ballman, Prazek, cfe-commits Differential Revision: https://reviews.llvm.org/D28034 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290492 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp')
-rw-r--r--unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index b7ffd75384..6037127feb 100644
--- a/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1404,6 +1404,16 @@ TEST(Member, BitFields) {
fieldDecl(isBitField(), hasBitWidth(2), hasName("a"))));
}
+TEST(Member, InClassInitializer) {
+ EXPECT_TRUE(
+ matches("class C { int a = 2; int b; };",
+ fieldDecl(hasInClassInitializer(integerLiteral(equals(2))),
+ hasName("a"))));
+ EXPECT_TRUE(
+ notMatches("class C { int a = 2; int b; };",
+ fieldDecl(hasInClassInitializer(anything()), hasName("b"))));
+}
+
TEST(Member, UnderstandsAccess) {
EXPECT_TRUE(matches(
"struct A { int i; };", fieldDecl(isPublic(), hasName("i"))));