[cfe-commits] r156078 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaObjCProperty.cpp test/SemaObjC/default-synthesize-1.m

Fariborz Jahanian fjahanian at apple.com
Thu May 3 09:43:30 PDT 2012


Author: fjahanian
Date: Thu May  3 11:43:30 2012
New Revision: 156078

URL: http://llvm.org/viewvc/llvm-project?rev=156078&view=rev
Log:
objective-c: warn for properties being default synthesized
under -Wobjc-missing-property-synthesis which must be
opted-in. // rdar://11295716

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=156078&r1=156077&r2=156078&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu May  3 11:43:30 2012
@@ -448,6 +448,8 @@
   "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 @@
   "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">;

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=156078&r1=156077&r2=156078&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Thu May  3 11:43:30 2012
@@ -1420,11 +1420,16 @@
     // 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);
+    }
   }
 }
 

Modified: cfe/trunk/test/SemaObjC/default-synthesize-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize-1.m?rev=156078&r1=156077&r2=156078&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/default-synthesize-1.m (original)
+++ cfe/trunk/test/SemaObjC/default-synthesize-1.m Thu May  3 11:43:30 2012
@@ -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
- at property int howMany;
- at property (retain) NSString* what;
+ at property int howMany; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
+ at property (retain) NSString* what; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
 @end
 
- at implementation SynthItAll
+ at implementation SynthItAll // expected-note 2 {{detected while default synthesizing properties in class implementation}}
 //@synthesize howMany, what;
 @end
 
 
 @interface SynthSetter : NSObject
- at property (nonatomic) int howMany;  // REM: nonatomic to avoid warnings about only implementing one of the pair
- at property (nonatomic, retain) NSString* what;
+ at property (nonatomic) int howMany;   // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
+ at property (nonatomic, retain) NSString* what;  // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
 @end
 
- at implementation SynthSetter
+ at 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
- at property (nonatomic) int howMany;  // REM: nonatomic to avoid warnings about only implementing one of the pair
- at property (nonatomic, retain) NSString* what;
+ at property (nonatomic) int howMany; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}} 
+ at property (nonatomic, retain) NSString* what; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
 @end
 
- at implementation SynthGetter
+ at 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}}
- at property struct B y; // expected-note {{forward declaration of 'struct B'}} expected-note {{property declared here}}
+ at 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
- at implementation rdar11333367 // expected-error {{cannot synthesize property 'y' with incomplete type 'struct B'}}
+ at 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





More information about the cfe-commits mailing list