r216408 - Objective-C. Allow [super initialize] in an +initialize
Fariborz Jahanian
fjahanian at apple.com
Mon Aug 25 14:27:38 PDT 2014
Author: fjahanian
Date: Mon Aug 25 16:27:38 2014
New Revision: 216408
URL: http://llvm.org/viewvc/llvm-project?rev=216408&view=rev
Log:
Objective-C. Allow [super initialize] in an +initialize
implementation but not anywhere else.
rdar://16628028
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/SemaObjC/warn-explicit-call-initialize.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=216408&r1=216407&r2=216408&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon Aug 25 16:27:38 2014
@@ -268,6 +268,7 @@ def ObjCRootClass : DiagGroup<"objc-root
def ObjCPointerIntrospectPerformSelector : DiagGroup<"deprecated-objc-pointer-introspection-performSelector">;
def ObjCPointerIntrospect : DiagGroup<"deprecated-objc-pointer-introspection", [ObjCPointerIntrospectPerformSelector]>;
def DeprecatedObjCIsaUsage : DiagGroup<"deprecated-objc-isa-usage">;
+def ExplicitInitializeCall : DiagGroup<"explicit-initialize-call">;
def Packed : DiagGroup<"packed">;
def Padded : DiagGroup<"padded">;
def PointerArith : DiagGroup<"pointer-arith">;
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=216408&r1=216407&r2=216408&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Aug 25 16:27:38 2014
@@ -6879,7 +6879,11 @@ def warn_ivar_use_hidden : Warning<
InGroup<DiagGroup<"shadow-ivar">>;
def warn_direct_initialize_call : Warning<
"explicit call to +initialize results in duplicate call to +initialize">,
- InGroup<DiagGroup<"explicit-initialize-call">>;
+ InGroup<ExplicitInitializeCall>;
+def warn_direct_super_initialize_call : Warning<
+ "explicit call to [super initialize] should only be in implementation "
+ "of +initialize">,
+ InGroup<ExplicitInitializeCall>;
def error_ivar_use_in_class_method : Error<
"instance variable %0 accessed in class method">;
def error_implicit_ivar_access : Error<
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=216408&r1=216407&r2=216408&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Mon Aug 25 16:27:38 2014
@@ -2237,14 +2237,25 @@ ExprResult Sema::BuildClassMessage(TypeS
return ExprError();
// Warn about explicit call of +initialize on its own class. But not on 'super'.
- if (Method && Method->getMethodFamily() == OMF_initialize &&
- !SuperLoc.isValid()) {
- const ObjCInterfaceDecl *ID =
- dyn_cast<ObjCInterfaceDecl>(Method->getDeclContext());
- if (ID == Class) {
- Diag(Loc, diag::warn_direct_initialize_call);
- Diag(Method->getLocation(), diag::note_method_declared_at)
- << Method->getDeclName();
+ if (Method && Method->getMethodFamily() == OMF_initialize) {
+ if (!SuperLoc.isValid()) {
+ const ObjCInterfaceDecl *ID =
+ dyn_cast<ObjCInterfaceDecl>(Method->getDeclContext());
+ if (ID == Class) {
+ Diag(Loc, diag::warn_direct_initialize_call);
+ Diag(Method->getLocation(), diag::note_method_declared_at)
+ << Method->getDeclName();
+ }
+ }
+ else if (ObjCMethodDecl *CurMeth = getCurMethodDecl()) {
+ // [super initialize] is allowed only within an +initialize implementation
+ if (CurMeth->getMethodFamily() != OMF_initialize) {
+ Diag(Loc, diag::warn_direct_super_initialize_call);
+ Diag(Method->getLocation(), diag::note_method_declared_at)
+ << Method->getDeclName();
+ Diag(CurMeth->getLocation(), diag::note_method_declared_at)
+ << CurMeth->getDeclName();
+ }
}
}
Modified: cfe/trunk/test/SemaObjC/warn-explicit-call-initialize.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-explicit-call-initialize.m?rev=216408&r1=216407&r2=216408&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-explicit-call-initialize.m (original)
+++ cfe/trunk/test/SemaObjC/warn-explicit-call-initialize.m Mon Aug 25 16:27:38 2014
@@ -2,11 +2,12 @@
// rdar://16628028
@interface NSObject
-+ (void)initialize; // expected-note {{method 'initialize' declared here}}
++ (void)initialize; // expected-note 2 {{method 'initialize' declared here}}
@end
@interface I : NSObject
+ (void)initialize; // expected-note {{method 'initialize' declared here}}
++ (void)SomeRandomMethod;
@end
@implementation I
@@ -17,5 +18,8 @@
+ (void)initialize {
[super initialize];
}
++ (void)SomeRandomMethod { // expected-note {{method 'SomeRandomMethod' declared here}}
+ [super initialize]; // expected-warning {{explicit call to [super initialize] should only be in implementation of +initialize}}
+}
@end
More information about the cfe-commits
mailing list