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
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">;
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;
// 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;
}
--- /dev/null
+// 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