summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/modernize-use-nullptr-basic.cpp
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2016-03-04 08:55:54 +0000
committerHaojian Wu <hokein@google.com>2016-03-04 08:55:54 +0000
commit678f65a9b4d808fe2f476c43d5acc884927c0377 (patch)
treec5d1accfdcec9198c3e7742bfb7c6519092bc221 /clang-tools-extra/test/clang-tidy/modernize-use-nullptr-basic.cpp
parent22bd871ea66538c1c21929828e2eca2185161c3e (diff)
downloadbcm5719-llvm-678f65a9b4d808fe2f476c43d5acc884927c0377.tar.gz
bcm5719-llvm-678f65a9b4d808fe2f476c43d5acc884927c0377.zip
[clang-tidy] Make 'modernize-use-nullptr' check work on multiple nested implicit cast expressions.
Summary: For some test cases like: ``` int func(int, void*, void*); (double)func(0, 0, 0); ``` The AST contains several `ImplicitCastExpr`s, so we should not only check on the first sub expression. ``` `-CStyleCastExpr 0x7fe43a088938 <line:6:3, col:24> 'double' <NoOp> `-ImplicitCastExpr 0x7fe43a088920 <col:11, col:24> 'double' <IntegralToFloating> `-CallExpr 0x7fe43a0888a0 <col:11, col:24> 'int' |-ImplicitCastExpr 0x7fe43a088888 <col:11> 'int (*)(int, void *, void *)' <FunctionToPointerDecay> | `-DeclRefExpr 0x7fe43a0887d8 <col:11> 'int (int, void *, void *)' lvalue Function 0x7fe43a0886f0 'func1' 'int (int, void *, void *)' |-IntegerLiteral 0x7fe43a088800 <col:17> 'int' 0 |-ImplicitCastExpr 0x7fe43a0888e0 <col:20> 'void *' <NullToPointer> | `-IntegerLiteral 0x7fe43a088820 <col:20> 'int' 0 `-ImplicitCastExpr 0x7fe43a0888f8 <col:23> 'void *' <NullToPointer> `-IntegerLiteral 0x7fe43a088840 <col:23> 'int' 0 ``` Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17849 llvm-svn: 262698
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/modernize-use-nullptr-basic.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/modernize-use-nullptr-basic.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/modernize-use-nullptr-basic.cpp b/clang-tools-extra/test/clang-tidy/modernize-use-nullptr-basic.cpp
index 6c317d761ac..7a953a70c77 100644
--- a/clang-tools-extra/test/clang-tidy/modernize-use-nullptr-basic.cpp
+++ b/clang-tools-extra/test/clang-tidy/modernize-use-nullptr-basic.cpp
@@ -327,6 +327,21 @@ void test_const_pointers() {
// CHECK-FIXES: const int *const_p6 = static_cast<int*>(t ? t : static_cast<int*>(nullptr));
}
+void test_nested_implicit_cast_expr() {
+ int func0(void*, void*);
+ int func1(int, void*, void*);
+
+ (double)func1(0, 0, 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use nullptr
+ // CHECK-MESSAGES: :[[@LINE-2]]:23: warning: use nullptr
+ // CHECK-FIXES: (double)func1(0, nullptr, nullptr);
+ (double)func1(func0(0, 0), 0, 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: use nullptr
+ // CHECK-MESSAGES: :[[@LINE-2]]:26: warning: use nullptr
+ // CHECK-MESSAGES: :[[@LINE-3]]:30: warning: use nullptr
+ // CHECK-MESSAGES: :[[@LINE-4]]:33: warning: use nullptr
+ // CHECK-FIXES: (double)func1(func0(nullptr, nullptr), nullptr, nullptr);
+}
// FIXME: currently, the check doesn't work as it should with templates.
template<typename T>
OpenPOWER on IntegriCloud