]> granicus.if.org Git - clang/commitdiff
Diagnose when method parameter is an object.
authorFariborz Jahanian <fjahanian@apple.com>
Sat, 17 Jan 2009 21:57:49 +0000 (21:57 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Sat, 17 Jan 2009 21:57:49 +0000 (21:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62431 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticKinds.def
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/method-bad-param.m [new file with mode: 0644]

index e1f0685d7422ba4f43746c221fca85ba4ed45184..fd5215e0cc9815e00e908746d9bfec47896f1343 100644 (file)
@@ -416,6 +416,8 @@ DIAG(err_expected_asm_operand, ERROR,
      "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")
 
index f6a245a3172cb9e552041fc340246f5a193312e8..d140b908a800b12615d0fd9766d91bed32630caf 100644 (file)
@@ -1349,6 +1349,11 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration(
       }
       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 (file)
index 0000000..34f71e7
--- /dev/null
@@ -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
+