]> granicus.if.org Git - clang/commitdiff
Add FixIt hint for missing 'id' type.
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 21 Jul 2011 17:38:14 +0000 (17:38 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 21 Jul 2011 17:38:14 +0000 (17:38 +0000)
// rdar://9615045

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

lib/Sema/SemaDeclObjC.cpp
test/FixIt/fixit-missing-method-return-type.m [new file with mode: 0644]

index 261d8efeb97362d1d003acf2f30afa5cb634bf4d..43f9c785926ae6f87048f27508e5b401e34de8b7 100644 (file)
@@ -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 (file)
index 0000000..214bdf8
--- /dev/null
@@ -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
+