blob: 3ba8d62b663fd9d2bed90052ae35f861e85d6f71 [file] [log] [blame]
Ted Kremenek34653182012-07-25 07:26:32 +00001// RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -verify %s
Nico Weber43bb1792012-06-28 23:53:12 +00002
3class S {
4 public:
5 int a_;
6 void s(int a) {
Nico Weber7c81b432012-07-03 02:03:06 +00007 a_ = a_; // expected-warning {{assigning field to itself}}
Nico Weber43bb1792012-06-28 23:53:12 +00008
9 // Don't really care about this one either way.
Nico Weber7c81b432012-07-03 02:03:06 +000010 this->a_ = a_; // expected-warning {{assigning field to itself}}
Nico Weber43bb1792012-06-28 23:53:12 +000011
12 a_ += a_; // Shouldn't warn.
13 }
14};
15
16void f0(S* s) {
17 // Would be nice to have, but not important.
18 s->a_ = s->a_;
19}
20
21void f1(S* s, S* t) {
22 // Shouldn't warn.
23 t->a_ = s->a_;
24}
25
26struct T {
27 S* s_;
28};
29
30void f2(T* t) {
31 // Would be nice to have, but even less important.
32 t->s_->a_ = t->s_->a_;
33}
34
35void f3(T* t, T* t2) {
36 // Shouldn't warn.
37 t2->s_->a_ = t->s_->a_;
38}
39
40void 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