Added tests for explicit casts expressions and explicit casts sequences.

Hi revane, tareqsiraj,

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

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D496?vs=1189&id=1190#toc

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

Index: cpp11-migrate/UseNullptr/NullptrActions.cpp
===================================================================
--- cpp11-migrate/UseNullptr/NullptrActions.cpp
+++ cpp11-migrate/UseNullptr/NullptrActions.cpp
@@ -110,8 +110,10 @@
 
   const CastExpr *Cast = Result.Nodes.getNodeAs<CastExpr>(ImplicitCastNode);
   if (Cast) {
-    SourceLocation StartLoc = Cast->getLocStart();
-    SourceLocation EndLoc = Cast->getLocEnd();
+    const Expr *E = Cast->IgnoreParenImpCasts();
+
+    SourceLocation StartLoc = E->getLocStart();
+    SourceLocation EndLoc = E->getLocEnd();
 
     // If the start/end location is a macro, get the expansion location.
     StartLoc = SM.getFileLoc(StartLoc);
Index: test/cpp11-migrate/UseNullptr/basic.cpp
===================================================================
--- test/cpp11-migrate/UseNullptr/basic.cpp
+++ test/cpp11-migrate/UseNullptr/basic.cpp
@@ -204,3 +204,34 @@
   // CHECK: my_macro(p != nullptr);
 #undef my_macro
 }
+
+// Test parentheses expressions resulting in a nullptr.
+int *test_parentheses_expression1() {
+  return(0);
+  // CHECK: return(nullptr);
+}
+
+int *test_parentheses_expression2() {
+  return(int(0.f));
+  // CHECK: return(nullptr);
+}
+
+int *test_nested_parentheses_expression() {
+  return((((0))));
+  // CHECK: return((((nullptr))));
+}
+
+void *test_parentheses_explicit_cast() {
+  return(static_cast<void*>(0));
+  // CHECK: return(nullptr);
+}
+
+void *test_parentheses_explicit_cast_sequence1() {
+  return(static_cast<void*>(static_cast<int*>((void*)NULL)));
+  // CHECK: return(nullptr);
+}
+
+void *test_parentheses_explicit_cast_sequence2() {
+  return(static_cast<void*>(reinterpret_cast<int*>((float*)int(0.f))));
+  // CHECK: return(nullptr);
+}
Index: cpp11-migrate/UseNullptr/NullptrActions.cpp
===================================================================
--- cpp11-migrate/UseNullptr/NullptrActions.cpp
+++ cpp11-migrate/UseNullptr/NullptrActions.cpp
@@ -110,8 +110,10 @@
 
   const CastExpr *Cast = Result.Nodes.getNodeAs<CastExpr>(ImplicitCastNode);
   if (Cast) {
-    SourceLocation StartLoc = Cast->getLocStart();
-    SourceLocation EndLoc = Cast->getLocEnd();
+    const Expr *E = Cast->IgnoreParenImpCasts();
+
+    SourceLocation StartLoc = E->getLocStart();
+    SourceLocation EndLoc = E->getLocEnd();
 
     // If the start/end location is a macro, get the expansion location.
     StartLoc = SM.getFileLoc(StartLoc);
Index: test/cpp11-migrate/UseNullptr/basic.cpp
===================================================================
--- test/cpp11-migrate/UseNullptr/basic.cpp
+++ test/cpp11-migrate/UseNullptr/basic.cpp
@@ -204,3 +204,34 @@
   // CHECK: my_macro(p != nullptr);
 #undef my_macro
 }
+
+// Test parentheses expressions resulting in a nullptr.
+int *test_parentheses_expression1() {
+  return(0);
+  // CHECK: return(nullptr);
+}
+
+int *test_parentheses_expression2() {
+  return(int(0.f));
+  // CHECK: return(nullptr);
+}
+
+int *test_nested_parentheses_expression() {
+  return((((0))));
+  // CHECK: return((((nullptr))));
+}
+
+void *test_parentheses_explicit_cast() {
+  return(static_cast<void*>(0));
+  // CHECK: return(nullptr);
+}
+
+void *test_parentheses_explicit_cast_sequence1() {
+  return(static_cast<void*>(static_cast<int*>((void*)NULL)));
+  // CHECK: return(nullptr);
+}
+
+void *test_parentheses_explicit_cast_sequence2() {
+  return(static_cast<void*>(reinterpret_cast<int*>((float*)int(0.f))));
+  // CHECK: return(nullptr);
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to