r209751 - Objective-C. Deprecate use of function definitions
Fariborz Jahanian
fjahanian at apple.com
Wed May 28 10:02:35 PDT 2014
Author: fjahanian
Date: Wed May 28 12:02:35 2014
New Revision: 209751
URL: http://llvm.org/viewvc/llvm-project?rev=209751&view=rev
Log:
Objective-C. Deprecate use of function definitions
in Objective-C container declarations (but not
in their definitions. // rdar://10414277
Added:
cfe/trunk/test/SemaObjC/deprecate_function_containers.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=209751&r1=209750&r2=209751&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Wed May 28 12:02:35 2014
@@ -242,6 +242,7 @@ def OverlengthStrings : DiagGroup<"overl
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">;
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=209751&r1=209750&r2=209751&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed May 28 12:02:35 2014
@@ -5817,6 +5817,10 @@ def err_cast_pointer_from_non_pointer_in
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;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=209751&r1=209750&r2=209751&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed May 28 12:02:35 2014
@@ -9797,6 +9797,11 @@ Decl *Sema::ActOnStartOfFunctionDef(Scop
// 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;
}
Added: cfe/trunk/test/SemaObjC/deprecate_function_containers.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/deprecate_function_containers.m?rev=209751&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/deprecate_function_containers.m (added)
+++ cfe/trunk/test/SemaObjC/deprecate_function_containers.m Wed May 28 12:02:35 2014
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
+// rdar://10414277
+
+ at protocol P
+void p_foo() {} // expected-warning {{function definition inside an Objective-C container is deprecated}}
+ at end
+
+ at 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}}
+ at end
+
+ at interface I(CAT)
+void cat_foo() {} // expected-warning {{function definition inside an Objective-C container is deprecated}}
+ at end
+
+ at implementation I
+inline void v_imp_foo() {}
+ at end
+
+ at implementation I(CAT)
+void cat_imp_foo() {}
+ at end
More information about the cfe-commits
mailing list