From: Fariborz Jahanian Date: Wed, 28 May 2014 17:02:35 +0000 (+0000) Subject: Objective-C. Deprecate use of function definitions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c09f3c51f733039c407665f9afd5ed843c033cf4;p=clang Objective-C. Deprecate use of function definitions 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 --- diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 485b48d380..230e021203 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -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">; diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 7e23d37bfa..86e8b3e741 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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; +def warn_function_def_in_objc_container : Warning< + "function definition inside an Objective-C container is deprecated">, + InGroup; + def warn_bad_function_cast : Warning< "cast from function call of type %0 to non-matching type %1">, InGroup, DefaultIgnore; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index a0ce7663a8..ede333d989 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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 index 0000000000..4bee742382 --- /dev/null +++ b/test/SemaObjC/deprecate_function_containers.m @@ -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