150
|
1 // RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -verify %s
|
|
2
|
|
3 class S {
|
|
4 public:
|
|
5 int a_;
|
|
6 void s(int a) {
|
|
7 a_ = a_; // expected-warning {{assigning field to itself}}
|
|
8
|
|
9 // Don't really care about this one either way.
|
|
10 this->a_ = a_; // expected-warning {{assigning field to itself}}
|
|
11
|
|
12 a_ += a_; // Shouldn't warn.
|
|
13 }
|
|
14 };
|
|
15
|
|
16 void f0(S* s) {
|
|
17 // Would be nice to have, but not important.
|
|
18 s->a_ = s->a_;
|
|
19 }
|
|
20
|
|
21 void f1(S* s, S* t) {
|
|
22 // Shouldn't warn.
|
|
23 t->a_ = s->a_;
|
|
24 }
|
|
25
|
|
26 struct T {
|
|
27 S* s_;
|
|
28 };
|
|
29
|
|
30 void f2(T* t) {
|
|
31 // Would be nice to have, but even less important.
|
|
32 t->s_->a_ = t->s_->a_;
|
|
33 }
|
|
34
|
|
35 void f3(T* t, T* t2) {
|
|
36 // Shouldn't warn.
|
|
37 t2->s_->a_ = t->s_->a_;
|
|
38 }
|
|
39
|
|
40 void f4(int i) {
|
|
41 // This is a common pattern to silence "parameter unused". Shouldn't warn.
|
|
42 i = i;
|
|
43
|
|
44 int j = 0;
|
|
45 j = j; // Likewise.
|
|
46 }
|
|
47
|
|
48 @interface I {
|
|
49 int a_;
|
|
50 }
|
|
51 @end
|
|
52
|
|
53 @implementation I
|
|
54 - (void)setA:(int)a {
|
|
55 a_ = a_; // expected-warning {{assigning instance variable to itself}}
|
|
56 }
|
|
57
|
|
58 - (void)foo:(I*)i {
|
|
59 // Don't care much about this warning.
|
|
60 i->a_ = i->a_; // expected-warning {{assigning instance variable to itself}}
|
|
61
|
|
62 // Shouldn't warn.
|
|
63 a_ = i->a_;
|
|
64 i->a_ = a_;
|
|
65 }
|
|
66 @end
|