Diagnose when method parameter is an object.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62431 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def
index e1f0685..fd5215e 100644
--- a/include/clang/Basic/DiagnosticKinds.def
+++ b/include/clang/Basic/DiagnosticKinds.def
@@ -416,6 +416,8 @@
      "expected string literal or '[' for asm operand")
 DIAG(err_expected_selector_for_method, ERROR,
      "expected selector for Objective-C method")
+DIAG(err_object_as_method_param, ERROR,
+     "can not use an object as parameter to a method")
 DIAG(err_nsobject_attribute, ERROR,
      "__attribute ((NSObject)) is for pointer types only")
 
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index f6a245a..d140b90 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -1349,6 +1349,11 @@
       }
       else if (argType->isFunctionType())
         argType = Context.getPointerType(argType);
+      else if (argType->isObjCInterfaceType()) {
+        // FIXME! provide more precise location for the parameter
+        Diag(MethodLoc, diag::err_object_as_method_param);
+        return 0;
+      }
     } else
       argType = Context.getObjCIdType();
     ParmVarDecl* Param;
diff --git a/test/SemaObjC/method-bad-param.m b/test/SemaObjC/method-bad-param.m
new file mode 100644
index 0000000..34f71e7
--- /dev/null
+++ b/test/SemaObjC/method-bad-param.m
@@ -0,0 +1,18 @@
+// RUN: clang -fsyntax-only -verify %s
+
+@interface foo
+@end
+
+@implementation foo
+@end
+
+@interface bar
+-(void) my_method:(foo) my_param; // expected-error {{can not use an object as parameter to a method}}
+@end
+
+@implementation bar
+-(void) my_method:(foo) my_param  // expected-error {{can not use an object as parameter to a method}}
+{
+}
+@end
+