Bug 1319903 - Part 1: Ignore ParenExpr's when ignoring trivial expressions; r=mystor
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 23 Nov 2016 15:17:41 -0500
changeset 324140 5e508878b3d81e2823246ebf85bb470762581a15
parent 324139 9935254c39eef9d14de419dd6163ff453cc1ce16
child 324141 96c3b7bcd5a7c4f53254e412e8a9af25e35ece01
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersmystor
bugs1319903
milestone53.0a1
Bug 1319903 - Part 1: Ignore ParenExpr's when ignoring trivial expressions; r=mystor
build/clang-plugin/clang-plugin.cpp
build/clang-plugin/tests/TestKungFuDeathGrip.cpp
--- a/build/clang-plugin/clang-plugin.cpp
+++ b/build/clang-plugin/clang-plugin.cpp
@@ -418,16 +418,18 @@ const Stmt *IgnoreImplicit(const Stmt *s
     if (auto *ewc = dyn_cast<ExprWithCleanups>(s)) {
       s = ewc->getSubExpr();
     } else if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s)) {
       s = mte->GetTemporaryExpr();
     } else if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s)) {
       s = bte->getSubExpr();
     } else if (auto *ice = dyn_cast<ImplicitCastExpr>(s)) {
       s = ice->getSubExpr();
+    } else if (auto *pe = dyn_cast<ParenExpr>(s)) {
+      s = pe->getSubExpr();
     } else {
       break;
     }
   }
 
   return s;
 }
 
--- a/build/clang-plugin/tests/TestKungFuDeathGrip.cpp
+++ b/build/clang-plugin/tests/TestKungFuDeathGrip.cpp
@@ -30,34 +30,36 @@ public:
 class Type {
 public:
   static nsCOMPtr<Type> someStaticCOMPtr;
 
   void f(nsCOMPtr<Type> ignoredArgument, Type *param) {
     nsCOMPtr<Type> never_referenced;
     nsCOMPtr<Type> kfdg_t1(this);
     nsCOMPtr<Type> kfdg_t2 = this;
+    nsCOMPtr<Type> kfdg_t3 = (this);
 
     nsCOMPtr<Type> kfdg_m1(p); // expected-error {{Unused "kungFuDeathGrip" 'nsCOMPtr<Type>' objects constructed from members are prohibited}} expected-note {{Please switch all accesses to this member to go through 'kfdg_m1', or explicitly pass 'kfdg_m1' to `mozilla::Unused`}}
     nsCOMPtr<Type> kfdg_m2 = p; // expected-error {{Unused "kungFuDeathGrip" 'nsCOMPtr<Type>' objects constructed from members are prohibited}} expected-note {{Please switch all accesses to this member to go through 'kfdg_m2', or explicitly pass 'kfdg_m2' to `mozilla::Unused`}}
     nsCOMPtr<Type> kfdg_m3(p);
     kfdg_m3.mPtr->f(nullptr, nullptr);
     nsCOMPtr<Type> kfdg_m4 = p;
     kfdg_m4.mPtr->f(nullptr, nullptr);
 
     nsCOMPtr<Type> kfdg_a1((already_AddRefed<Type>()));
     nsCOMPtr<Type> kfdg_a2 = already_AddRefed<Type>();
 
     nsCOMPtr<Type> kfdg_p1(param);
     nsCOMPtr<Type> kfdg_p2 = param;
 
 
     RefPtr<Type> never_referenced2;
-    RefPtr<Type> kfdg_t3(this);
-    RefPtr<Type> kfdg_t4 = this;
+    RefPtr<Type> kfdg_t4(this);
+    RefPtr<Type> kfdg_t5 = this;
+    RefPtr<Type> kfdg_t6 = (this);
 
     RefPtr<Type> kfdg_m5(p); // expected-error {{Unused "kungFuDeathGrip" 'RefPtr<Type>' objects constructed from members are prohibited}} expected-note {{Please switch all accesses to this member to go through 'kfdg_m5', or explicitly pass 'kfdg_m5' to `mozilla::Unused`}}
     RefPtr<Type> kfdg_m6 = p; // expected-error {{Unused "kungFuDeathGrip" 'RefPtr<Type>' objects constructed from members are prohibited}} expected-note {{Please switch all accesses to this member to go through 'kfdg_m6', or explicitly pass 'kfdg_m6' to `mozilla::Unused`}}
     RefPtr<Type> kfdg_m7(p);
     kfdg_m7.mPtr->f(nullptr, nullptr);
     RefPtr<Type> kfdg_m8 = p;
     kfdg_m8.mPtr->f(nullptr, nullptr);