summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-06-19 22:51:22 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-06-19 22:51:22 +0000
commit63d40202fb478b331abeddcf2b12517f42db0f86 (patch)
tree814a8bab559e66a443c5d6a088b545fcd55c2ce5
parent2db1125b151f229cb0a5f25ed9b41a716f14eb20 (diff)
downloadbcm5719-llvm-63d40202fb478b331abeddcf2b12517f42db0f86.tar.gz
bcm5719-llvm-63d40202fb478b331abeddcf2b12517f42db0f86.zip
objective-c: warn when autosynthesizing a property which has same
name as an existing ivar since this is common source of error when people remove @synthesize to take advantage of autosynthesis. // rdar://11671080 llvm-svn: 158756
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--clang/lib/Sema/SemaObjCProperty.cpp16
-rw-r--r--clang/test/SemaObjC/default-synthesize-2.m7
3 files changed, 23 insertions, 3 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9ca078d1bd9..d27acf7b996 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -630,6 +630,9 @@ def warn_auto_synthesizing_protocol_property :Warning<
"auto property synthesis will not synthesize property"
" declared in a protocol">,
InGroup<DiagGroup<"objc-protocol-property-synthesis">>;
+def warn_autosynthesis_property_ivar_match :Warning<
+ "auto autosynthesized property has same name as an existing ivar">,
+ InGroup<DiagGroup<"objc-autosynthesis-property-ivar-name-match">>;
def warn_missing_explicit_synthesis : Warning <
"auto property synthesis is synthesizing property not explicitly synthesized">,
InGroup<DiagGroup<"objc-missing-property-synthesis">>, DefaultIgnore;
diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp
index 84dc9cae233..20dbf58c986 100644
--- a/clang/lib/Sema/SemaObjCProperty.cpp
+++ b/clang/lib/Sema/SemaObjCProperty.cpp
@@ -755,6 +755,22 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S,
}
if (!Ivar) {
+ if (AtLoc.isInvalid()) {
+ // Check when default synthesizing a property that there is
+ // an ivar matching property name and issue warning; since this
+ // is the most common case of not using an ivar used for backing
+ // property in non-default synthesis case.
+ ObjCInterfaceDecl *ClassDeclared=0;
+ ObjCIvarDecl *originalIvar =
+ IDecl->lookupInstanceVariable(property->getIdentifier(),
+ ClassDeclared);
+ if (originalIvar) {
+ Diag(PropertyDiagLoc,
+ diag::warn_autosynthesis_property_ivar_match);
+ Diag(property->getLocation(), diag::note_property_declare);
+ Diag(originalIvar->getLocation(), diag::note_ivar_decl);
+ }
+ }
// In ARC, give the ivar a lifetime qualifier based on the
// property attributes.
if (getLangOpts().ObjCAutoRefCount &&
diff --git a/clang/test/SemaObjC/default-synthesize-2.m b/clang/test/SemaObjC/default-synthesize-2.m
index b95f263c32d..eeeab5f5c46 100644
--- a/clang/test/SemaObjC/default-synthesize-2.m
+++ b/clang/test/SemaObjC/default-synthesize-2.m
@@ -41,12 +41,13 @@
// Test3
@interface Test3
{
- id uid;
+ id uid; // expected-note {{ivar is declared here}}
}
-@property (readwrite, assign) id uid;
+@property (readwrite, assign) id uid; // expected-note {{property declared here}}
@end
-@implementation Test3
+// rdar://11671080
+@implementation Test3 // expected-warning {{auto autosynthesized property has same name as an existing ivar}}
// Oops, forgot to write @synthesize! will be default synthesized
- (void) myMethod {
self.uid = 0; // Use of the “setter”
OpenPOWER on IntegriCloud