diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2011-07-21 17:00:47 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2011-07-21 17:00:47 +0000 |
commit | aab24a616de59c543d78d7636f22fb786053fefa (patch) | |
tree | 11caaf20a3c5b30f2f6276a8f1d9ce486985ddfb | |
parent | 1a23f12e1e283384b76e768a83f01bfcbbd61ca0 (diff) |
objc - Diagnose missing method return type specifier under
a warning flag. // rdar://9615045
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135681 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticGroups.td | 2 | ||||
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 3 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 4 | ||||
-rw-r--r-- | test/SemaObjC/missing-method-return-type.m | 11 |
4 files changed, 19 insertions, 1 deletions
diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index e86efecfad..7f8c382c34 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -108,6 +108,7 @@ def ReturnType : DiagGroup<"return-type">; def BindToTemporaryCopy : DiagGroup<"bind-to-temporary-copy">; def SelfAssignment : DiagGroup<"self-assign">; def SemiBeforeMethodBody : DiagGroup<"semicolon-before-method-body">; +def MissingMethodReturnType : DiagGroup<"missing-method-return-type">; def : DiagGroup<"sequence-point">; def Shadow : DiagGroup<"shadow">; def : DiagGroup<"shorten-64-to-32">; @@ -243,6 +244,7 @@ def Extra : DiagGroup<"extra", [ IgnoredQualifiers, InitializerOverrides, SemiBeforeMethodBody, + MissingMethodReturnType, SignCompare, UnusedParameter ]>; diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index fec587e4ae..0987494ea3 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -4339,6 +4339,9 @@ def warn_attribute_method_def : Warning< def ext_typecheck_base_super : Warning< "method parameter type %0 does not match " "super class method parameter type %1">, InGroup<SuperSubClassMismatch>, DefaultIgnore; +def warn_missing_method_return_type : Warning< + "method has no return type specified; defaults to 'id'">, + InGroup<MissingMethodReturnType>, DefaultIgnore; // Spell-checking diagnostics def err_unknown_typename_suggest : Error< diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index aa8152b03b..261d8efeb9 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -2298,8 +2298,10 @@ Decl *Sema::ActOnMethodDeclaration( << 0 << resultDeclType; return 0; } - } else // get the type for "id". + } else { // get the type for "id". resultDeclType = Context.getObjCIdType(); + Diag(MethodLoc, diag::warn_missing_method_return_type); + } ObjCMethodDecl* ObjCMethod = ObjCMethodDecl::Create(Context, MethodLoc, EndLoc, Sel, resultDeclType, diff --git a/test/SemaObjC/missing-method-return-type.m b/test/SemaObjC/missing-method-return-type.m new file mode 100644 index 0000000000..b62a0466ad --- /dev/null +++ b/test/SemaObjC/missing-method-return-type.m @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -Wmissing-method-return-type -fsyntax-only -verify %s +// rdar://9615045 + +@interface I +- initWithFoo:(id)foo; // expected-warning {{method has no return type specified; defaults to 'id' [-Wmissing-method-return-type]}} +@end + +@implementation I +- initWithFoo:(id)foo { return 0; } // expected-warning {{method has no return type specified; defaults to 'id' [-Wmissing-method-return-type]}} +@end + |