]> granicus.if.org Git - clang/commitdiff
Objective-C. Deprecate use of function definitions
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 28 May 2014 17:02:35 +0000 (17:02 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 28 May 2014 17:02:35 +0000 (17:02 +0000)
in Objective-C container declarations (but not
in their definitions. // rdar://10414277

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209751 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/SemaObjC/deprecate_function_containers.m [new file with mode: 0644]

index 485b48d38092a8c72336530942c9c81782e012bd..230e0212032025d9618fb6a38ea456dd8a080fee 100644 (file)
@@ -242,6 +242,7 @@ def OverlengthStrings : DiagGroup<"overlength-strings">;
 def OverloadedVirtual : DiagGroup<"overloaded-virtual">;
 def PrivateExtern : DiagGroup<"private-extern">;
 def SelTypeCast : DiagGroup<"cast-of-sel-type">;
+def FunctionDefInObjCContainer : DiagGroup<"function-def-in-objc-container">;
 def BadFunctionCast : DiagGroup<"bad-function-cast">;
 def ObjCPropertyImpl : DiagGroup<"objc-property-implementation">;
 def ObjCPropertyNoAttribute : DiagGroup<"objc-property-no-attribute">;
index 7e23d37bfa4d4354d763b74c0ff33a692c213c34..86e8b3e741368e514c0c1907318412b64cb25b48 100644 (file)
@@ -5817,6 +5817,10 @@ def err_cast_pointer_from_non_pointer_int : Error<
 def warn_cast_pointer_from_sel : Warning<
   "cast of type %0 to %1 is deprecated; use sel_getName instead">,
   InGroup<SelTypeCast>;
+def warn_function_def_in_objc_container : Warning<
+  "function definition inside an Objective-C container is deprecated">,
+  InGroup<FunctionDefInObjCContainer>;
+  
 def warn_bad_function_cast : Warning<
   "cast from function call of type %0 to non-matching type %1">,
   InGroup<BadFunctionCast>, DefaultIgnore;
index a0ce7663a8276afca257d5c9f8f8d9b4b1cd5439..ede333d98912941555ae7d7387f0067d267491da 100644 (file)
@@ -9797,6 +9797,11 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D) {
   // We want to attach documentation to original Decl (which might be
   // a function template).
   ActOnDocumentableDecl(D);
+  if (getCurLexicalContext()->isObjCContainer() &&
+      getCurLexicalContext()->getDeclKind() != Decl::ObjCCategoryImpl &&
+      getCurLexicalContext()->getDeclKind() != Decl::ObjCImplementation)
+    Diag(FD->getLocation(), diag::warn_function_def_in_objc_container);
+    
   return D;
 }
 
diff --git a/test/SemaObjC/deprecate_function_containers.m b/test/SemaObjC/deprecate_function_containers.m
new file mode 100644 (file)
index 0000000..4bee742
--- /dev/null
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1  -fsyntax-only -verify -Wno-objc-root-class %s
+// rdar://10414277
+
+@protocol P
+void p_foo() {} // expected-warning {{function definition inside an Objective-C container is deprecated}}
+@end
+
+@interface I
+void foo() {} // expected-warning {{function definition inside an Objective-C container is deprecated}}
+inline void v_foo() {} // expected-warning {{function definition inside an Objective-C container is deprecated}}
+static int s_foo() {return 0; } // expected-warning {{function definition inside an Objective-C container is deprecated}}
+static inline int si_val() { return 1; } // expected-warning {{function definition inside an Objective-C container is deprecated}}
+@end
+
+@interface I(CAT)
+void cat_foo() {} // expected-warning {{function definition inside an Objective-C container is deprecated}}
+@end
+
+@implementation I
+inline void v_imp_foo() {} 
+@end
+
+@implementation I(CAT)
+void cat_imp_foo() {} 
+@end