- Simplified Matcher with Edwin's comments
- Added a new test case with a chain of explicit casts with condition within.
Hi revane, tareqsiraj,
http://llvm-reviews.chandlerc.com/D627
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D627?vs=1512&id=1532#toc
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
@@ -58,10 +58,12 @@
);
return castExpr(
- unless(hasAncestor(explicitCastExpr())),
anyOf(
- hasDescendant(ImplicitCastToNull),
- ImplicitCastToNull
- )
+ ImplicitCastToNull,
+ explicitCastExpr(
+ hasDescendant(ImplicitCastToNull)
+ )
+ ),
+ unless(hasAncestor(explicitCastExpr()))
).bind(CastSequence);
}
Index: test/cpp11-migrate/UseNullptr/basic.cpp
===================================================================
--- test/cpp11-migrate/UseNullptr/basic.cpp
+++ test/cpp11-migrate/UseNullptr/basic.cpp
@@ -221,6 +221,8 @@
void ambiguous_function(int *a) {}
void ambiguous_function(float *a) {}
+void const_ambiguous_function(const int *p) {}
+void const_ambiguous_function(const float *p) {}
void test_explicit_cast_ambiguous1() {
ambiguous_function((int*)0);
@@ -251,3 +253,26 @@
k = (int*)0;
// CHECK: k = (int*)nullptr;
}
+
+void test_const_pointers_abiguous() {
+ const_ambiguous_function((int*)0);
+ // CHECK: const_ambiguous_function((int*)nullptr);
+}
+
+// Test where the implicit cast to null is surrounded by another implict cast
+// with possible explict casts in-between
+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;
+ int *t;
+ const int *const_p6 = static_cast<int*>(t ? t : static_cast<int*>(0));
+ // CHECK: const int *const_p6 = static_cast<int*>(t ? t :
static_cast<int*>(nullptr));
+}
Index: cpp11-migrate/UseNullptr/NullptrMatchers.cpp
===================================================================
--- cpp11-migrate/UseNullptr/NullptrMatchers.cpp
+++ cpp11-migrate/UseNullptr/NullptrMatchers.cpp
@@ -58,10 +58,12 @@
);
return castExpr(
- unless(hasAncestor(explicitCastExpr())),
anyOf(
- hasDescendant(ImplicitCastToNull),
- ImplicitCastToNull
- )
+ ImplicitCastToNull,
+ explicitCastExpr(
+ hasDescendant(ImplicitCastToNull)
+ )
+ ),
+ unless(hasAncestor(explicitCastExpr()))
).bind(CastSequence);
}
Index: test/cpp11-migrate/UseNullptr/basic.cpp
===================================================================
--- test/cpp11-migrate/UseNullptr/basic.cpp
+++ test/cpp11-migrate/UseNullptr/basic.cpp
@@ -221,6 +221,8 @@
void ambiguous_function(int *a) {}
void ambiguous_function(float *a) {}
+void const_ambiguous_function(const int *p) {}
+void const_ambiguous_function(const float *p) {}
void test_explicit_cast_ambiguous1() {
ambiguous_function((int*)0);
@@ -251,3 +253,26 @@
k = (int*)0;
// CHECK: k = (int*)nullptr;
}
+
+void test_const_pointers_abiguous() {
+ const_ambiguous_function((int*)0);
+ // CHECK: const_ambiguous_function((int*)nullptr);
+}
+
+// Test where the implicit cast to null is surrounded by another implict cast
+// with possible explict casts in-between
+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;
+ int *t;
+ const int *const_p6 = static_cast<int*>(t ? t : static_cast<int*>(0));
+ // CHECK: const int *const_p6 = static_cast<int*>(t ? t : static_cast<int*>(nullptr));
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits