[PATCH] D26301: [clang-tidy] Fix a regression issue introduced by r285239.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 7 13:56:09 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL286156: [clang-tidy] Fix a regression issue introduced by r285239. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D26301?vs=76920&id=77096#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26301

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp


Index: clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -190,13 +190,21 @@
   // within a cast expression.
   bool VisitStmt(Stmt *S) {
     CastExpr *C = dyn_cast<CastExpr>(S);
+    // Catch the castExpr inside cxxDefaultArgExpr.
+    if (auto *E = dyn_cast<CXXDefaultArgExpr>(S))
+      C = dyn_cast<CastExpr>(E->getExpr());
     if (!C) {
       FirstSubExpr = nullptr;
       return true;
     }
+
     if (!FirstSubExpr)
       FirstSubExpr = C->getSubExpr()->IgnoreParens();
 
+    // Ignore the expr if it is already a nullptr literal expr.
+    if (isa<CXXNullPtrLiteralExpr>(FirstSubExpr))
+      return true;
+
     if (C->getCastKind() != CK_NullToPointer &&
         C->getCastKind() != CK_NullToMemberPointer) {
       return true;
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp
@@ -217,3 +217,14 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use nullptr
 // CHECK-FIXES: C<bool, F(nullptr)> c;
 #undef F
+
+// Test default argument expression.
+struct D {
+  explicit D(void *t, int *c = NULL) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: use nullptr
+  // CHECK-FIXES: explicit D(void *t, int *c = nullptr) {}
+};
+
+void test_default_argument() {
+  D(nullptr);
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26301.77096.patch
Type: text/x-patch
Size: 1649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161107/052592b2/attachment-0001.bin>


More information about the cfe-commits mailing list