diff options
-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 + |