]> granicus.if.org Git - clang/commitdiff
Do not treat @selector as lvalue (unlike g++).
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 17 Jun 2010 21:45:48 +0000 (21:45 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 17 Jun 2010 21:45:48 +0000 (21:45 +0000)
Patch by Nico Weber (pr7390).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106242 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
lib/Sema/SemaExpr.cpp
test/CodeGenCXX/sel-address.mm [new file with mode: 0644]
test/CodeGenObjCXX/selactor-expr-lvalue.mm

index 1d715b004d705ea4f43f5a16acffa5fc2f3c6d3f..e36ae41ce46ec872defee3135a021a84c734c148 100644 (file)
@@ -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).
index ae56018b99acc54581c2fc5849259ccfc28a1935..fa403c78d06642f8a72750f78adea6a628b17678 100644 (file)
@@ -6060,6 +6060,8 @@ QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) {
       << op->getType() << op->getSourceRange();
     if (isSFINAEContext())
       return QualType();
+  } else if (isa<ObjCSelectorExpr>(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 (file)
index 0000000..c3db9a7
--- /dev/null
@@ -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);
+}
index 69b82e92f2285d1fe30403bcf8fc5c505491843e..030545119be430b9e4de438a6657b30be91c7183 100644 (file)
@@ -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