From 678f65a9b4d808fe2f476c43d5acc884927c0377 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 4 Mar 2016 08:55:54 +0000 Subject: [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 'double' `-ImplicitCastExpr 0x7fe43a088920 'double' `-CallExpr 0x7fe43a0888a0 'int' |-ImplicitCastExpr 0x7fe43a088888 'int (*)(int, void *, void *)' | `-DeclRefExpr 0x7fe43a0887d8 'int (int, void *, void *)' lvalue Function 0x7fe43a0886f0 'func1' 'int (int, void *, void *)' |-IntegerLiteral 0x7fe43a088800 'int' 0 |-ImplicitCastExpr 0x7fe43a0888e0 'void *' | `-IntegerLiteral 0x7fe43a088820 'int' 0 `-ImplicitCastExpr 0x7fe43a0888f8 'void *' `-IntegerLiteral 0x7fe43a088840 'int' 0 ``` Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17849 llvm-svn: 262698 --- .../test/clang-tidy/modernize-use-nullptr-basic.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'clang-tools-extra/test/clang-tidy/modernize-use-nullptr-basic.cpp') 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(t ? t : static_cast(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 -- cgit v1.2.3