diff options
author | Adam Balogh <adam.balogh@ericsson.com> | 2017-11-23 12:43:20 +0000 |
---|---|---|
committer | Adam Balogh <adam.balogh@ericsson.com> | 2017-11-23 12:43:20 +0000 |
commit | be065bce297cc2dd2773caf4346c218d04492913 (patch) | |
tree | 35e24f0b6e4e31add4e8e5ba5309932445289525 /unittests | |
parent | 6428eaf621c44d0cf2c16536e6e28c796feed958 (diff) |
[ASTMatchers] Matchers for new[] operators
Two new matchers for `CXXNewExpr` are added which may be useful e.g. in
`clang-tidy` checkers. One of them is `isArray` which matches `new[]` but not
plain `new`. The other one, `hasArraySize` matches `new[]` for a given size.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@318909 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp index 9c9304a6f8..f6b217c0cb 100644 --- a/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -1998,5 +1998,15 @@ TEST(HasDefaultArgument, Basic) { parmVarDecl(hasDefaultArgument()))); } +TEST(IsArray, Basic) { + EXPECT_TRUE(matches("struct MyClass {}; MyClass *p1 = new MyClass[10];", + cxxNewExpr(isArray()))); +} + +TEST(HasArraySize, Basic) { + EXPECT_TRUE(matches("struct MyClass {}; MyClass *p1 = new MyClass[10];", + cxxNewExpr(hasArraySize(integerLiteral(equals(10)))))); +} + } // namespace ast_matchers } // namespace clang |