[cfe-commits] r135681 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclObjC.cpp test/SemaObjC/missing-method-return-type.m
Fariborz Jahanian
fjahanian at apple.com
Thu Jul 21 10:00:47 PDT 2011
Author: fjahanian
Date: Thu Jul 21 12:00:47 2011
New Revision: 135681
URL: http://llvm.org/viewvc/llvm-project?rev=135681&view=rev
Log:
objc - Diagnose missing method return type specifier under
a warning flag. // rdar://9615045
Added:
cfe/trunk/test/SemaObjC/missing-method-return-type.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=135681&r1=135680&r2=135681&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Thu Jul 21 12:00:47 2011
@@ -108,6 +108,7 @@
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 @@
IgnoredQualifiers,
InitializerOverrides,
SemiBeforeMethodBody,
+ MissingMethodReturnType,
SignCompare,
UnusedParameter
]>;
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=135681&r1=135680&r2=135681&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jul 21 12:00:47 2011
@@ -4339,6 +4339,9 @@
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<
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=135681&r1=135680&r2=135681&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Jul 21 12:00:47 2011
@@ -2298,8 +2298,10 @@
<< 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,
Added: cfe/trunk/test/SemaObjC/missing-method-return-type.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/missing-method-return-type.m?rev=135681&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/missing-method-return-type.m (added)
+++ cfe/trunk/test/SemaObjC/missing-method-return-type.m Thu Jul 21 12:00:47 2011
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -Wmissing-method-return-type -fsyntax-only -verify %s
+// rdar://9615045
+
+ at interface I
+- initWithFoo:(id)foo; // expected-warning {{method has no return type specified; defaults to 'id' [-Wmissing-method-return-type]}}
+ at end
+
+ at implementation I
+- initWithFoo:(id)foo { return 0; } // expected-warning {{method has no return type specified; defaults to 'id' [-Wmissing-method-return-type]}}
+ at end
+
More information about the cfe-commits
mailing list