From: Fariborz Jahanian Date: Thu, 21 Jul 2011 17:38:14 +0000 (+0000) Subject: Add FixIt hint for missing 'id' type. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=feb4fa165c5e8c40ffc8b1b655cc3c8071862b20;p=clang Add FixIt hint for missing 'id' type. // rdar://9615045 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135685 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 261d8efeb9..43f9c78592 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -2300,7 +2300,8 @@ Decl *Sema::ActOnMethodDeclaration( } } else { // get the type for "id". resultDeclType = Context.getObjCIdType(); - Diag(MethodLoc, diag::warn_missing_method_return_type); + Diag(MethodLoc, diag::warn_missing_method_return_type) + << FixItHint::CreateInsertion(SelectorStartLoc, "(id)"); } ObjCMethodDecl* ObjCMethod = diff --git a/test/FixIt/fixit-missing-method-return-type.m b/test/FixIt/fixit-missing-method-return-type.m new file mode 100644 index 0000000000..214bdf80b0 --- /dev/null +++ b/test/FixIt/fixit-missing-method-return-type.m @@ -0,0 +1,24 @@ +// Objective-C recovery +// RUN: cp %s %t +// RUN: %clang_cc1 -Wmissing-method-return-type -fixit -x objective-c %t || true +// RUN: %clang_cc1 -fsyntax-only -pedantic -Wmissing-method-return-type -Werror -x objective-c %t + +// Objective-C++ recovery +// RUN: cp %s %t +// RUN: %clang_cc1 -Wmissing-method-return-type -fixit -x objective-c++ %t || true +// RUN: %clang_cc1 -fsyntax-only -pedantic -Wmissing-method-return-type -Werror -x objective-c++ %t +// rdar://9615045 + +@interface I +- initWithFoo:(id)foo; // expected-warning {{method has no return type specified; defaults to 'id' [-Wmissing-method-return-type]}} +- Meth; +-Meth1; +@end + +@implementation I +- initWithFoo:(id)foo { return 0; } // expected-warning {{method has no return type specified; defaults to 'id' [-Wmissing-method-return-type]}} + +-Meth { return 0;} +- Meth1 { return 0;} +@end +