aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-05-03 16:43:30 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-05-03 16:43:30 +0000
commit975eef64182a78d1afc0f3da8cba4cb961cda5e4 (patch)
tree6a2f80f30340e85c6128d841e39ad315920689fa
parent0cf3c0eecbff007cea2750c113894b47d9e09f33 (diff)
objective-c: warn for properties being default synthesized
under -Wobjc-missing-property-synthesis which must be opted-in. // rdar://11295716 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156078 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td5
-rw-r--r--lib/Sema/SemaObjCProperty.cpp15
-rw-r--r--test/SemaObjC/default-synthesize-1.m27
3 files changed, 30 insertions, 17 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 9d6cc726c2..31fb03c2e4 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -448,6 +448,8 @@ def err_class_extension_after_impl : Error<
"cannot declare class extension for %0 after class implementation">;
def note_implementation_declared : Note<
"class implementation is declared here">;
+def not_while_in_implementation : Note<
+ "detected while default synthesizing properties in class implementation">;
def note_class_declared : Note<
"class is declared here">;
def note_receiver_is_id : Note<
@@ -618,6 +620,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_missing_explicit_synthesis : Warning <
+ "auto property synthesis is synthesizing property not explicitly synthesized">,
+ InGroup<DiagGroup<"objc-missing-property-synthesis">>, DefaultIgnore;
def warn_property_getter_owning_mismatch : Warning<
"property declared as returning non-retained objects"
"; getter returning retained objects">;
diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp
index 0ae2a21495..9f9c96046a 100644
--- a/lib/Sema/SemaObjCProperty.cpp
+++ b/lib/Sema/SemaObjCProperty.cpp
@@ -1420,11 +1420,16 @@ void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl,
// aren't really synthesized at a particular location; they just exist.
// Saying that they are located at the @implementation isn't really going
// to help users.
- ActOnPropertyImplDecl(S, SourceLocation(), SourceLocation(),
- true,
- /* property = */ Prop->getIdentifier(),
- /* ivar = */ getDefaultSynthIvarName(Prop, Context),
- SourceLocation());
+ ObjCPropertyImplDecl *PIDecl = dyn_cast_or_null<ObjCPropertyImplDecl>(
+ ActOnPropertyImplDecl(S, SourceLocation(), SourceLocation(),
+ true,
+ /* property = */ Prop->getIdentifier(),
+ /* ivar = */ getDefaultSynthIvarName(Prop, Context),
+ SourceLocation()));
+ if (PIDecl) {
+ Diag(Prop->getLocation(), diag::warn_missing_explicit_synthesis);
+ Diag(IMPDecl->getLocation(), diag::not_while_in_implementation);
+ }
}
}
diff --git a/test/SemaObjC/default-synthesize-1.m b/test/SemaObjC/default-synthesize-1.m
index ddefcdeef2..5aaca9a1c2 100644
--- a/test/SemaObjC/default-synthesize-1.m
+++ b/test/SemaObjC/default-synthesize-1.m
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -Wobjc-missing-property-synthesis -verify -Wno-objc-root-class %s
+// rdar://11295716
@interface NSObject
- (void) release;
@@ -7,21 +8,21 @@
@class NSString;
@interface SynthItAll : NSObject
-@property int howMany;
-@property (retain) NSString* what;
+@property int howMany; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
+@property (retain) NSString* what; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
@end
-@implementation SynthItAll
+@implementation SynthItAll // expected-note 2 {{detected while default synthesizing properties in class implementation}}
//@synthesize howMany, what;
@end
@interface SynthSetter : NSObject
-@property (nonatomic) int howMany; // REM: nonatomic to avoid warnings about only implementing one of the pair
-@property (nonatomic, retain) NSString* what;
+@property (nonatomic) int howMany; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
+@property (nonatomic, retain) NSString* what; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
@end
-@implementation SynthSetter
+@implementation SynthSetter // expected-note 2 {{detected while default synthesizing properties in class implementation}}
//@synthesize howMany, what;
- (int) howMany {
@@ -37,11 +38,11 @@
@interface SynthGetter : NSObject
-@property (nonatomic) int howMany; // REM: nonatomic to avoid warnings about only implementing one of the pair
-@property (nonatomic, retain) NSString* what;
+@property (nonatomic) int howMany; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
+@property (nonatomic, retain) NSString* what; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
@end
-@implementation SynthGetter
+@implementation SynthGetter // expected-note 2 {{detected while default synthesizing properties in class implementation}}
//@synthesize howMany, what;
// - (int) howMany
@@ -116,8 +117,10 @@
@interface rdar11333367
@property enum A x; // expected-note {{forward declaration of 'enum A'}} expected-note {{property declared here}}
-@property struct B y; // expected-note {{forward declaration of 'struct B'}} expected-note {{property declared here}}
+@property struct B y; // expected-note {{forward declaration of 'struct B'}} expected-note {{property declared here}} \
+ // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
@end
-@implementation rdar11333367 // expected-error {{cannot synthesize property 'y' with incomplete type 'struct B'}}
+@implementation rdar11333367 // expected-error {{cannot synthesize property 'y' with incomplete type 'struct B'}} \
+ // expected-note {{detected while default synthesizing properties in class implementation}}
@synthesize x; // expected-error {{cannot synthesize property 'x' with incomplete type 'enum A'}}
@end