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