xref: /minix3/external/bsd/llvm/dist/clang/test/SemaObjC/idiomatic-parentheses.m (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -verify -Wparentheses -Wno-objc-root-class %s
2*f4a2713aSLionel Sambuc
3*f4a2713aSLionel Sambuc// Don't warn about some common ObjC idioms unless we have -Widiomatic-parentheses on.
4*f4a2713aSLionel Sambuc// <rdar://problem/7382435>
5*f4a2713aSLionel Sambuc
6*f4a2713aSLionel Sambuc@interface Object
7*f4a2713aSLionel Sambuc{
8*f4a2713aSLionel Sambuc  unsigned uid;
9*f4a2713aSLionel Sambuc}
10*f4a2713aSLionel Sambuc- (id) init;
11*f4a2713aSLionel Sambuc- (id) initWithInt: (int) i;
12*f4a2713aSLionel Sambuc- (id) myInit __attribute__((objc_method_family(init)));
13*f4a2713aSLionel Sambuc- (void) iterate: (id) coll;
14*f4a2713aSLionel Sambuc- (id) nextObject;
15*f4a2713aSLionel Sambuc@property unsigned uid;
16*f4a2713aSLionel Sambuc@end
17*f4a2713aSLionel Sambuc
18*f4a2713aSLionel Sambuc@implementation Object
19*f4a2713aSLionel Sambuc@synthesize uid;
20*f4a2713aSLionel Sambuc- (id) init {
21*f4a2713aSLionel Sambuc  if (self = [self init]) {
22*f4a2713aSLionel Sambuc  }
23*f4a2713aSLionel Sambuc  return self;
24*f4a2713aSLionel Sambuc}
25*f4a2713aSLionel Sambuc
26*f4a2713aSLionel Sambuc- (id) initWithInt: (int) i {
27*f4a2713aSLionel Sambuc  if (self = [self initWithInt: i]) {
28*f4a2713aSLionel Sambuc  }
29*f4a2713aSLionel Sambuc  // rdar://11066598
30*f4a2713aSLionel Sambuc  if (self.uid = 100) { // expected-warning {{using the result of an assignment as a condition without parentheses}} \
31*f4a2713aSLionel Sambuc                        // expected-note {{place parentheses around the assignment to silence this warning}} \
32*f4a2713aSLionel Sambuc                        // expected-note {{use '==' to turn this assignment into an equality comparison}}
33*f4a2713aSLionel Sambuc        // ...
34*f4a2713aSLionel Sambuc  }
35*f4a2713aSLionel Sambuc  return self;
36*f4a2713aSLionel Sambuc}
37*f4a2713aSLionel Sambuc
38*f4a2713aSLionel Sambuc- (id) myInit {
39*f4a2713aSLionel Sambuc  if (self = [self myInit]) {
40*f4a2713aSLionel Sambuc  }
41*f4a2713aSLionel Sambuc  return self;
42*f4a2713aSLionel Sambuc}
43*f4a2713aSLionel Sambuc
44*f4a2713aSLionel Sambuc- (void) iterate: (id) coll {
45*f4a2713aSLionel Sambuc  id cur;
46*f4a2713aSLionel Sambuc  while (cur = [coll nextObject]) {
47*f4a2713aSLionel Sambuc  }
48*f4a2713aSLionel Sambuc}
49*f4a2713aSLionel Sambuc
50*f4a2713aSLionel Sambuc- (id) nextObject {
51*f4a2713aSLionel Sambuc  return self;
52*f4a2713aSLionel Sambuc}
53*f4a2713aSLionel Sambuc@end
54