Let Expr::HasSideEffects() return false for NULL, bool literals, this, and nullptr.

Fixes PR13413, -Wunused-private-field now warns on unused fields initialized to NULL.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160541 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index f88206c..cbcd5e8 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -2340,6 +2340,12 @@
     return Visit(E->getSubExpr());
   }
   bool VisitUnaryOperator(const UnaryOperator *E) { return Visit(E->getSubExpr()); }
+  bool VisitGNUNullExpr(const GNUNullExpr *E) { return false; }
+  bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) { return false; }
+  bool VisitCXXThisExpr(const CXXThisExpr *E) { return false; }
+  bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E) {
+    return false;
+  }
     
   // Has side effects if any element does.
   bool VisitInitListExpr(const InitListExpr *E) {
diff --git a/test/ARCMT/cxx-rewrite.mm.result b/test/ARCMT/cxx-rewrite.mm.result
index a2dc9a5..7c944d5 100644
--- a/test/ARCMT/cxx-rewrite.mm.result
+++ b/test/ARCMT/cxx-rewrite.mm.result
@@ -16,7 +16,7 @@
             [NSString string];
         }
     }
-    ~foo(){ s; }
+    ~foo(){  }
 private:
     foo(foo const &);
     foo &operator=(foo const &);
diff --git a/test/SemaCXX/warn-unused-private-field.cpp b/test/SemaCXX/warn-unused-private-field.cpp
index 6a7922e..640a9b9 100644
--- a/test/SemaCXX/warn-unused-private-field.cpp
+++ b/test/SemaCXX/warn-unused-private-field.cpp
@@ -209,3 +209,13 @@
   unsigned char Data[8];
 };
 }  // namespace anonymous_structs_unions
+
+namespace pr13413 {
+class A {
+  A() : p_(__null), b_(false), a_(this), p2_(nullptr) {}
+  void* p_;  // expected-warning{{private field 'p_' is not used}}
+  bool b_;  // expected-warning{{private field 'b_' is not used}}
+  A* a_;  // expected-warning{{private field 'a_' is not used}}
+  void* p2_;  // expected-warning{{private field 'p2_' is not used}}
+};
+}