[clang-tools-extra] r286156 - [clang-tidy] Fix a regression issue introduced by r285239.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 7 13:46:24 PST 2016
Author: hokein
Date: Mon Nov 7 15:46:24 2016
New Revision: 286156
URL: http://llvm.org/viewvc/llvm-project?rev=286156&view=rev
Log:
[clang-tidy] Fix a regression issue introduced by r285239.
Summary:
r285239 changes the behavior of AST CXXDefaultArgExpr node.
Update `modernize-use-nullptr` to handle CXXDefaultArgExpr correctly.
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D26301
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=286156&r1=286155&r2=286156&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp Mon Nov 7 15:46:24 2016
@@ -190,13 +190,21 @@ public:
// 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;
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=286156&r1=286155&r2=286156&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 Mon Nov 7 15:46:24 2016
@@ -217,3 +217,14 @@ C<bool, F(0)> c;
// 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);
+}
More information about the cfe-commits
mailing list