diff options
author | Nico Weber <nicolasweber@gmx.de> | 2012-06-28 23:53:12 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2012-06-28 23:53:12 +0000 |
commit | 33fd523df145e0e6f0f975ab2b9e727735a963f6 (patch) | |
tree | c1071d90b4ce6451e2250a1fb2004764a461d3a9 /clang/test | |
parent | 474112d82c7b92ea8d5ecdeaf89c9e4db34e1a4a (diff) | |
download | bcm5719-llvm-33fd523df145e0e6f0f975ab2b9e727735a963f6.tar.gz bcm5719-llvm-33fd523df145e0e6f0f975ab2b9e727735a963f6.zip |
Warn on self-assignment to member variables. PR13104.
llvm-svn: 159394
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Sema/warn-self-assign-memvar.mm | 66 | ||||
-rw-r--r-- | clang/test/SemaObjC/provisional-ivar-lookup.m | 2 |
2 files changed, 67 insertions, 1 deletions
diff --git a/clang/test/Sema/warn-self-assign-memvar.mm b/clang/test/Sema/warn-self-assign-memvar.mm new file mode 100644 index 00000000000..8c6fb0a5a0b --- /dev/null +++ b/clang/test/Sema/warn-self-assign-memvar.mm @@ -0,0 +1,66 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +class S { + public: + int a_; + void s(int a) { + a_ = a_; // expected-warning {{assigning member variable to itself}} + + // Don't really care about this one either way. + this->a_ = a_; // expected-warning {{assigning member variable to itself}} + + a_ += a_; // Shouldn't warn. + } +}; + +void f0(S* s) { + // Would be nice to have, but not important. + s->a_ = s->a_; +} + +void f1(S* s, S* t) { + // Shouldn't warn. + t->a_ = s->a_; +} + +struct T { + S* s_; +}; + +void f2(T* t) { + // Would be nice to have, but even less important. + t->s_->a_ = t->s_->a_; +} + +void f3(T* t, T* t2) { + // Shouldn't warn. + t2->s_->a_ = t->s_->a_; +} + +void f4(int i) { + // This is a common pattern to silence "parameter unused". Shouldn't warn. + i = i; + + int j = 0; + j = j; // Likewise. +} + +@interface I { + int a_; +} +@end + +@implementation I +- (void)setA:(int)a { + a_ = a_; // expected-warning {{assigning instance variable to itself}} +} + +- (void)foo:(I*)i { + // Don't care much about this warning. + i->a_ = i->a_; // expected-warning {{assigning instance variable to itself}} + + // Shouldn't warn. + a_ = i->a_; + i->a_ = a_; +} +@end diff --git a/clang/test/SemaObjC/provisional-ivar-lookup.m b/clang/test/SemaObjC/provisional-ivar-lookup.m index 2ec23a55c37..7460fc2e206 100644 --- a/clang/test/SemaObjC/provisional-ivar-lookup.m +++ b/clang/test/SemaObjC/provisional-ivar-lookup.m @@ -36,7 +36,7 @@ @synthesize PROP=PROP; - (void)setPROP:(int)value { - PROP = PROP; // OK + PROP = value; // OK } @end |