67 lines · plain
1// RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -verify %s2 3class 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 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@end52 53@implementation I54- (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@end67