[clang-tools-extra] r296479 - [clang-tidy] Fix a false positive on modernize-use-nullptr check.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 28 07:29:52 PST 2017
Author: hokein
Date: Tue Feb 28 09:29:52 2017
New Revision: 296479
URL: http://llvm.org/viewvc/llvm-project?rev=296479&view=rev
Log:
[clang-tidy] Fix a false positive on modernize-use-nullptr check.
Summary:
The false positive happens on two neighbour CXXDefaultArgExpr AST nodes.
like below:
```
CXXFunctionalCastExpr 0x85c9670 <col:7, col:23> 'struct ZZ' functional cast to struct ZZ <ConstructorConversion>
`-CXXConstructExpr 0x85c9518 <col:7, col:23> 'struct ZZ' 'void (uint64, const uint64 *)'
|-CallExpr 0x85a0a90 <col:10, col:22> 'uint64':'unsigned long long'
| |-ImplicitCastExpr 0x85a0a78 <col:10> 'uint64 (*)(uint64)' <FunctionToPointerDecay>
| | `-DeclRefExpr 0x85a09f0 <col:10> 'uint64 (uint64)' lvalue Function 0x85a06a0 'Hash' 'uint64 (uint64)'
| `-CXXDefaultArgExpr 0x85a0ac8 <<invalid sloc>> 'uint64':'unsigned long long'
`-CXXDefaultArgExpr 0x85c94f8 <<invalid sloc>> 'const uint64 *'
```
For each particular CXXDefaultArgExpr node, we need to reset
FirstSubExpr, otherwise FirstSubExpr will refer to an incorrect expr.
Reviewers: alexfh
Reviewed By: alexfh
Subscribers: JDevlieghere, cfe-commits
Differential Revision: https://reviews.llvm.org/D30412
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.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=296479&r1=296478&r2=296479&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp Tue Feb 28 09:29:52 2017
@@ -190,8 +190,10 @@ public:
bool VisitStmt(Stmt *S) {
auto *C = dyn_cast<CastExpr>(S);
// Catch the castExpr inside cxxDefaultArgExpr.
- if (auto *E = dyn_cast<CXXDefaultArgExpr>(S))
+ if (auto *E = dyn_cast<CXXDefaultArgExpr>(S)) {
C = dyn_cast<CastExpr>(E->getExpr());
+ FirstSubExpr = nullptr;
+ }
if (!C) {
FirstSubExpr = nullptr;
return true;
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp?rev=296479&r1=296478&r2=296479&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp Tue Feb 28 09:29:52 2017
@@ -228,3 +228,19 @@ struct D {
void test_default_argument() {
D(nullptr);
}
+
+// Test on two neighbour CXXDefaultArgExprs nodes.
+typedef unsigned long long uint64;
+struct ZZ {
+ explicit ZZ(uint64, const uint64* = NULL) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:39: warning: use nullptr
+// CHECK-FIXES: explicit ZZ(uint64, const uint64* = nullptr) {}
+ operator bool() { return true; }
+};
+
+uint64 Hash(uint64 seed = 0) { return 0; }
+
+void f() {
+ bool a;
+ a = ZZ(Hash());
+}
More information about the cfe-commits
mailing list