aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-07-21 17:38:14 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-07-21 17:38:14 +0000
commitfeb4fa165c5e8c40ffc8b1b655cc3c8071862b20 (patch)
tree4893707fc2ebbc2ae22e5ed4180b09f5b96f3c8b
parentaab24a616de59c543d78d7636f22fb786053fefa (diff)
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
-rw-r--r--lib/Sema/SemaDeclObjC.cpp3
-rw-r--r--test/FixIt/fixit-missing-method-return-type.m24
2 files changed, 26 insertions, 1 deletions
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
+