diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-01-17 21:57:49 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-01-17 21:57:49 +0000 |
commit | 9bae5e7af04e44b4d333a2c7ba22608d0594ff9f (patch) | |
tree | f0a5d526c259a49289b5ce24caf9225fc22df92c | |
parent | f54b19497cb832da78700a6c86473231f35fba65 (diff) |
Diagnose when method parameter is an object.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62431 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticKinds.def | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 5 | ||||
-rw-r--r-- | test/SemaObjC/method-bad-param.m | 18 |
3 files changed, 25 insertions, 0 deletions
diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index e1f0685d74..fd5215e0cc 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -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") diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index f6a245a317..d140b908a8 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -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 index 0000000000..34f71e76a5 --- /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 + |