diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-05-22 21:42:52 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-05-22 21:42:52 +0000 |
commit | b5ff6bfaf4bff6c70042600ad4070518440cec4a (patch) | |
tree | 58fd2b3f461fc5c821c73c06f79814657e63a6bf | |
parent | c25d8058958d9cda0d9d6216b475180ba2f7c71d (diff) |
Cannot type cast @selector expressions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72284 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 2 | ||||
-rw-r--r-- | test/SemaObjC/selector-error.m | 20 |
3 files changed, 24 insertions, 0 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 9e7e94f085..49cadcd1a7 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1423,6 +1423,8 @@ def err_typecheck_expect_scalar_operand : Error< "operand of type %0 where arithmetic or pointer type is required">; def err_typecheck_cond_incompatible_operands : Error< "incompatible operand types (%0 and %1)">; +def err_cast_selector_expr : Error< + "cannot type cast @selector expression">; def warn_typecheck_cond_incompatible_pointers : Warning< "pointer type mismatch (%0 and %1)">; def warn_typecheck_cond_pointer_integer_mismatch : Warning< diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index c9acb48e85..574955789c 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2820,6 +2820,8 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr) { diag::err_cast_pointer_to_non_pointer_int) << castType << castExpr->getSourceRange(); } + if (isa<ObjCSelectorExpr>(castExpr)) + return Diag(castExpr->getLocStart(), diag::err_cast_selector_expr); return false; } diff --git a/test/SemaObjC/selector-error.m b/test/SemaObjC/selector-error.m new file mode 100644 index 0000000000..cc2a404726 --- /dev/null +++ b/test/SemaObjC/selector-error.m @@ -0,0 +1,20 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +@interface Foo +- (char*) foo; +- (void) bar; +@end + +@implementation Foo +- (void) bar +{ +} + +- (char*) foo +{ + char* a,b,c; + a = (char*)@selector(bar); // expected-error {{cannot type cast @selector expression}} + return (char*)@selector(bar); // expected-error {{cannot type cast @selector expression}} +} +@end + |