]> granicus.if.org Git - clang/commitdiff
objective-c: warn for properties being default synthesized
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 3 May 2012 16:43:30 +0000 (16:43 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 3 May 2012 16:43:30 +0000 (16:43 +0000)
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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaObjCProperty.cpp
test/SemaObjC/default-synthesize-1.m

index 9d6cc726c28831c5e4b82a651c94d08b616702f3..31fb03c2e4206b29bd5123d5fadf132818b867b9 100644 (file)
@@ -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">;
index 0ae2a21495e39f3586eb425edc6c02d9fde599c8..9f9c96046aa34c49180e39678ff11a1e2972b03d 100644 (file)
@@ -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);
+    }
   }
 }
 
index ddefcdeef29716378bc365be782b47ef55f2b687..5aaca9a1c2911e3f4279af0e7fec6d50f171e843 100644 (file)
@@ -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 {
 
 
 @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
 
 @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