Hi revane, tareqsiraj,

UseNullptr previously matched the implicit cast to const pointer and the 
explicit cast within that has an implicit cast to nullptr as a descendant. 
This patch skips implicit casts expressions that have an implicit cast to 
nullptr within, so we only match the explicit cast.

Added test cases.

http://llvm-reviews.chandlerc.com/D627

Files:
  cpp11-migrate/UseNullptr/NullptrMatchers.cpp
  test/cpp11-migrate/UseNullptr/basic.cpp

Index: cpp11-migrate/UseNullptr/NullptrMatchers.cpp
===================================================================
--- cpp11-migrate/UseNullptr/NullptrMatchers.cpp
+++ cpp11-migrate/UseNullptr/NullptrMatchers.cpp
@@ -59,6 +59,7 @@
 
   return castExpr(
            unless(hasAncestor(explicitCastExpr())),
+           unless(implicitCastExpr(hasDescendant(ImplicitCastToNull))),
            anyOf(
              hasDescendant(ImplicitCastToNull),
              ImplicitCastToNull
Index: test/cpp11-migrate/UseNullptr/basic.cpp
===================================================================
--- test/cpp11-migrate/UseNullptr/basic.cpp
+++ test/cpp11-migrate/UseNullptr/basic.cpp
@@ -251,3 +251,26 @@
   k = (int*)0;
   // CHECK: k = (int*)nullptr;
 }
+
+// Test assignments to const pointers
+void test_const_pointers() {
+  const int *const_p1 = 0;
+  // CHECK: const int *const_p1 = nullptr;
+  const int *const_p2 = NULL;
+  // CHECK: const int *const_p2 = nullptr;
+  const int *const_p3 = (int)0;
+  // CHECK: const int *const_p3 = nullptr;
+  const int *const_p4 = (int)0.0f;
+  // CHECK: const int *const_p4 = nullptr;
+  const int *const_p5 = (int*)0;
+  // CHECK: const int *const_p5 = (int*)nullptr;
+}
+
+// Test for ambiguous funcions with const pointer arguments
+void const_ambiguous_function(const int *p) {}
+void const_ambiguous_function(const float *p) {}
+
+void test_const_pointers_abiguous() {
+  const_ambiguous_function((int*)0);
+  // CHECK: const_ambiguous_function((int*)nullptr);
+}
Index: cpp11-migrate/UseNullptr/NullptrMatchers.cpp
===================================================================
--- cpp11-migrate/UseNullptr/NullptrMatchers.cpp
+++ cpp11-migrate/UseNullptr/NullptrMatchers.cpp
@@ -59,6 +59,7 @@
 
   return castExpr(
            unless(hasAncestor(explicitCastExpr())),
+           unless(implicitCastExpr(hasDescendant(ImplicitCastToNull))),
            anyOf(
              hasDescendant(ImplicitCastToNull),
              ImplicitCastToNull
Index: test/cpp11-migrate/UseNullptr/basic.cpp
===================================================================
--- test/cpp11-migrate/UseNullptr/basic.cpp
+++ test/cpp11-migrate/UseNullptr/basic.cpp
@@ -251,3 +251,26 @@
   k = (int*)0;
   // CHECK: k = (int*)nullptr;
 }
+
+// Test assignments to const pointers
+void test_const_pointers() {
+  const int *const_p1 = 0;
+  // CHECK: const int *const_p1 = nullptr;
+  const int *const_p2 = NULL;
+  // CHECK: const int *const_p2 = nullptr;
+  const int *const_p3 = (int)0;
+  // CHECK: const int *const_p3 = nullptr;
+  const int *const_p4 = (int)0.0f;
+  // CHECK: const int *const_p4 = nullptr;
+  const int *const_p5 = (int*)0;
+  // CHECK: const int *const_p5 = (int*)nullptr;
+}
+
+// Test for ambiguous funcions with const pointer arguments
+void const_ambiguous_function(const int *p) {}
+void const_ambiguous_function(const float *p) {}
+
+void test_const_pointers_abiguous() {
+  const_ambiguous_function((int*)0);
+  // CHECK: const_ambiguous_function((int*)nullptr);
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to