]> granicus.if.org Git - clang/commitdiff
objc - Diagnose missing method return type specifier under
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 21 Jul 2011 17:00:47 +0000 (17:00 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 21 Jul 2011 17:00:47 +0000 (17:00 +0000)
a warning flag. // rdar://9615045

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

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/missing-method-return-type.m [new file with mode: 0644]

index e86efecfadf08490a250812da690ef035fbfe265..7f8c382c348d72e50f0c24d2ce83780040b44110 100644 (file)
@@ -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
   ]>;
index fec587e4ae18b344041e379437548a3efeefaa49..0987494ea38ea9dff7c1399febafb29c3ffa59b8 100644 (file)
@@ -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<
index aa8152b03b0a73ccc2f3662b0f7ea2f71d6175f9..261d8efeb97362d1d003acf2f30afa5cb634bf4d 100644 (file)
@@ -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 (file)
index 0000000..b62a046
--- /dev/null
@@ -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
+