From: Fariborz Jahanian Date: Thu, 17 Jun 2010 21:45:48 +0000 (+0000) Subject: Do not treat @selector as lvalue (unlike g++). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=949bd4b611f4be575d63da36c94c3662dfa4d459;p=clang Do not treat @selector as lvalue (unlike g++). Patch by Nico Weber (pr7390). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106242 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 1d715b004d..e36ae41ce4 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1194,7 +1194,6 @@ Expr::isLvalueResult Expr::isLvalueInternal(ASTContext &Ctx) const { case ObjCIsaExprClass: case StringLiteralClass: // C99 6.5.1p4 case ObjCEncodeExprClass: // @encode behaves like its string in every way. - case ObjCSelectorExprClass: // @selector return LV_Valid; case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2)))) // For vectors, make sure base is an lvalue (i.e. not a function call). diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index ae56018b99..fa403c78d0 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -6060,6 +6060,8 @@ QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) { << op->getType() << op->getSourceRange(); if (isSFINAEContext()) return QualType(); + } else if (isa(op)) { + return Context.getPointerType(op->getType()); } else if (lval != Expr::LV_Valid && lval != Expr::LV_IncompleteVoidType) { // C99 6.5.3.2p1 // The operand must be either an l-value or a function designator diff --git a/test/CodeGenCXX/sel-address.mm b/test/CodeGenCXX/sel-address.mm new file mode 100644 index 0000000000..c3db9a7d00 --- /dev/null +++ b/test/CodeGenCXX/sel-address.mm @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 %s -verify -emit-llvm -o %t +// pr7390 + +void f(const SEL& v2) {} +void g() { + f(@selector(dealloc)); + + SEL s = @selector(dealloc); + SEL* ps = &s; + + @selector(dealloc) = s; // expected-error {{expression is not assignable}} + + SEL* ps2 = &@selector(dealloc); +} diff --git a/test/CodeGenObjCXX/selactor-expr-lvalue.mm b/test/CodeGenObjCXX/selactor-expr-lvalue.mm index 69b82e92f2..030545119b 100644 --- a/test/CodeGenObjCXX/selactor-expr-lvalue.mm +++ b/test/CodeGenObjCXX/selactor-expr-lvalue.mm @@ -2,7 +2,7 @@ // PR7390 @interface NSObject {} -- (void)respondsToSelector:(SEL&)s : (SEL*)s1; +- (void)respondsToSelector:(const SEL&)s : (SEL*)s1; - (void) setPriority:(int)p; - (void)Meth; @end @@ -12,5 +12,5 @@ [self respondsToSelector:@selector(setPriority:) : &@selector(setPriority:)]; } - (void) setPriority:(int)p{} -- (void)respondsToSelector:(SEL&)s : (SEL*)s1 {} +- (void)respondsToSelector:(const SEL&)s : (SEL*)s1 {} @end