Skip to content
Snippets Groups Projects
Commit 975eef64 authored by Fariborz Jahanian's avatar Fariborz Jahanian
Browse files

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
parent 0cf3c0ee
No related branches found
No related tags found
No related merge requests found
...@@ -448,6 +448,8 @@ def err_class_extension_after_impl : Error< ...@@ -448,6 +448,8 @@ def err_class_extension_after_impl : Error<
"cannot declare class extension for %0 after class implementation">; "cannot declare class extension for %0 after class implementation">;
def note_implementation_declared : Note< def note_implementation_declared : Note<
"class implementation is declared here">; "class implementation is declared here">;
def not_while_in_implementation : Note<
"detected while default synthesizing properties in class implementation">;
def note_class_declared : Note< def note_class_declared : Note<
"class is declared here">; "class is declared here">;
def note_receiver_is_id : Note< def note_receiver_is_id : Note<
...@@ -618,6 +620,9 @@ def warn_auto_synthesizing_protocol_property :Warning< ...@@ -618,6 +620,9 @@ def warn_auto_synthesizing_protocol_property :Warning<
"auto property synthesis will not synthesize property" "auto property synthesis will not synthesize property"
" declared in a protocol">, " declared in a protocol">,
InGroup<DiagGroup<"objc-protocol-property-synthesis">>; 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< def warn_property_getter_owning_mismatch : Warning<
"property declared as returning non-retained objects" "property declared as returning non-retained objects"
"; getter returning retained objects">; "; getter returning retained objects">;
......
...@@ -1420,11 +1420,16 @@ void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl, ...@@ -1420,11 +1420,16 @@ void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl,
// aren't really synthesized at a particular location; they just exist. // aren't really synthesized at a particular location; they just exist.
// Saying that they are located at the @implementation isn't really going // Saying that they are located at the @implementation isn't really going
// to help users. // to help users.
ActOnPropertyImplDecl(S, SourceLocation(), SourceLocation(), ObjCPropertyImplDecl *PIDecl = dyn_cast_or_null<ObjCPropertyImplDecl>(
true, ActOnPropertyImplDecl(S, SourceLocation(), SourceLocation(),
/* property = */ Prop->getIdentifier(), true,
/* ivar = */ getDefaultSynthIvarName(Prop, Context), /* property = */ Prop->getIdentifier(),
SourceLocation()); /* ivar = */ getDefaultSynthIvarName(Prop, Context),
SourceLocation()));
if (PIDecl) {
Diag(Prop->getLocation(), diag::warn_missing_explicit_synthesis);
Diag(IMPDecl->getLocation(), diag::not_while_in_implementation);
}
} }
} }
......
// 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 @interface NSObject
- (void) release; - (void) release;
...@@ -7,21 +8,21 @@ ...@@ -7,21 +8,21 @@
@class NSString; @class NSString;
@interface SynthItAll : NSObject @interface SynthItAll : NSObject
@property int howMany; @property int howMany; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
@property (retain) NSString* what; @property (retain) NSString* what; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
@end @end
@implementation SynthItAll @implementation SynthItAll // expected-note 2 {{detected while default synthesizing properties in class implementation}}
//@synthesize howMany, what; //@synthesize howMany, what;
@end @end
@interface SynthSetter : NSObject @interface SynthSetter : NSObject
@property (nonatomic) int howMany; // REM: nonatomic to avoid warnings about only implementing one of the pair @property (nonatomic) int howMany; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
@property (nonatomic, retain) NSString* what; @property (nonatomic, retain) NSString* what; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
@end @end
@implementation SynthSetter @implementation SynthSetter // expected-note 2 {{detected while default synthesizing properties in class implementation}}
//@synthesize howMany, what; //@synthesize howMany, what;
- (int) howMany { - (int) howMany {
...@@ -37,11 +38,11 @@ ...@@ -37,11 +38,11 @@
@interface SynthGetter : NSObject @interface SynthGetter : NSObject
@property (nonatomic) int howMany; // REM: nonatomic to avoid warnings about only implementing one of the pair @property (nonatomic) int howMany; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
@property (nonatomic, retain) NSString* what; @property (nonatomic, retain) NSString* what; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
@end @end
@implementation SynthGetter @implementation SynthGetter // expected-note 2 {{detected while default synthesizing properties in class implementation}}
//@synthesize howMany, what; //@synthesize howMany, what;
// - (int) howMany // - (int) howMany
...@@ -116,8 +117,10 @@ ...@@ -116,8 +117,10 @@
@interface rdar11333367 @interface rdar11333367
@property enum A x; // expected-note {{forward declaration of 'enum A'}} expected-note {{property declared here}} @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 @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'}} @synthesize x; // expected-error {{cannot synthesize property 'x' with incomplete type 'enum A'}}
@end @end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment