[cfe-commits] r162846 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjC/idiomatic-parentheses.m

Fariborz Jahanian fjahanian at apple.com
Wed Aug 29 10:17:12 PDT 2012


Author: fjahanian
Date: Wed Aug 29 12:17:11 2012
New Revision: 162846

URL: http://llvm.org/viewvc/llvm-project?rev=162846&view=rev
Log:
objective-C: make -Widiomatic-parentheses work
when assignment expression in conditional invloves
property reference. // rdar://11066598

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaObjC/idiomatic-parentheses.m

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=162846&r1=162845&r2=162846&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Aug 29 12:17:11 2012
@@ -11191,7 +11191,9 @@
 
     IsOrAssign = Op->getOperator() == OO_PipeEqual;
     Loc = Op->getOperatorLoc();
-  } else {
+  } else if (PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(E))
+    return DiagnoseAssignmentAsCondition(POE->getSyntacticForm());
+  else {
     // Not an assignment.
     return;
   }

Modified: cfe/trunk/test/SemaObjC/idiomatic-parentheses.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/idiomatic-parentheses.m?rev=162846&r1=162845&r2=162846&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/idiomatic-parentheses.m (original)
+++ cfe/trunk/test/SemaObjC/idiomatic-parentheses.m Wed Aug 29 12:17:11 2012
@@ -4,13 +4,18 @@
 // <rdar://problem/7382435>
 
 @interface Object 
+{
+  unsigned uid;
+}
 - (id) init;
 - (id) initWithInt: (int) i;
 - (void) iterate: (id) coll;
 - (id) nextObject;
+ at property unsigned uid;
 @end
 
 @implementation Object
+ at synthesize uid;
 - (id) init {
   if (self = [self init]) {
   }
@@ -20,6 +25,12 @@
 - (id) initWithInt: (int) i {
   if (self = [self initWithInt: i]) {
   }
+  // rdar://11066598
+  if (self.uid = 100) { // expected-warning {{using the result of an assignment as a condition without parentheses}} \
+                        // expected-note {{place parentheses around the assignment to silence this warning}} \
+                        // expected-note {{use '==' to turn this assignment into an equality comparison}}
+        // ...
+  }
   return self;
 }
 





More information about the cfe-commits mailing list