Author: hokein Date: Fri Mar 4 02:55:54 2016 New Revision: 262698 URL: http://llvm.org/viewvc/llvm-project?rev=262698&view=rev Log: [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 Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr-basic.cpp Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp?rev=262698&r1=262697&r2=262698&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp Fri Mar 4 02:55:54 2016 @@ -252,7 +252,7 @@ public: } replaceWithNullptr(Check, SM, StartLoc, EndLoc); - return skipSubTree(); + return true; } private: Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr-basic.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr-basic.cpp?rev=262698&r1=262697&r2=262698&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr-basic.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr-basic.cpp Fri Mar 4 02:55:54 2016 @@ -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> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits