diff options
author | Clement Courbet <courbet@google.com> | 2018-11-22 14:00:56 +0000 |
---|---|---|
committer | Clement Courbet <courbet@google.com> | 2018-11-22 14:00:56 +0000 |
commit | c022c51f89cd6bc5df9d06ea3e4dacf225429347 (patch) | |
tree | 00fd7d7e25a71c3857b8fc9c8ffb5a5836102360 /clang/unittests | |
parent | 509f7d7c30ab76a046382cea731537ab061b889d (diff) |
[ASTMatchers] Add hasSideEffect() matcher.
Summary: Exposes Expr::HasSideEffects.
Reviewers: aaron.ballman
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D54830
llvm-svn: 347462
Diffstat (limited to 'clang/unittests')
-rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp index e37bcbeec1f3..076d21a1f5ea 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -2259,5 +2259,21 @@ TEST(Matcher, isMain) { notMatches("int main2() {}", functionDecl(isMain()))); } +TEST(Matcher, hasSideEffects) { + EXPECT_TRUE(matches("void call();" + "void f() { call(); }", + expr(hasSideEffects()))); + EXPECT_TRUE(matches("void f(int& a) { a = 0; }", expr(hasSideEffects()))); + EXPECT_TRUE( + matches("void f(volatile int a) { (void)a; }", expr(hasSideEffects()))); + + EXPECT_TRUE(notMatches("void call();" + "void f() { }", + expr(hasSideEffects()))); + EXPECT_TRUE( + notMatches("void f(int& a) { (void)a; }", expr(hasSideEffects()))); + EXPECT_TRUE(notMatches("void f(int a) { (void)a; }", expr(hasSideEffects()))); +} + } // namespace ast_matchers } // namespace clang |