[cfe-commits] r83562 - in /cfe/trunk: lib/AST/Expr.cpp test/SemaCXX/builtin-ptrtomember-overload-1.cpp test/SemaCXX/member-pointer.cpp

Fariborz Jahanian fjahanian at apple.com
Thu Oct 8 11:00:39 PDT 2009


Author: fjahanian
Date: Thu Oct  8 13:00:39 2009
New Revision: 83562

URL: http://llvm.org/viewvc/llvm-project?rev=83562&view=rev
Log:
Implement [expr.mptr.oper]p6 for '->*' operator.


Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/test/SemaCXX/builtin-ptrtomember-overload-1.cpp
    cfe/trunk/test/SemaCXX/member-pointer.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=83562&r1=83561&r2=83562&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Thu Oct  8 13:00:39 2009
@@ -922,11 +922,21 @@
       return BinOp->getRHS()->isLvalue(Ctx);
 
     // C++ [expr.mptr.oper]p6
-    if ((BinOp->getOpcode() == BinaryOperator::PtrMemD ||
-         BinOp->getOpcode() == BinaryOperator::PtrMemI) &&
+    // The result of a .* expression is an lvalue only if its first operand is 
+    // an lvalue and its second operand is a pointer to data member. 
+    if (BinOp->getOpcode() == BinaryOperator::PtrMemD &&
         !BinOp->getType()->isFunctionType())
       return BinOp->getLHS()->isLvalue(Ctx);
 
+    // The result of an ->* expression is an lvalue only if its second operand 
+    // is a pointer to data member.
+    if (BinOp->getOpcode() == BinaryOperator::PtrMemI &&
+        !BinOp->getType()->isFunctionType()) {
+      QualType Ty = BinOp->getRHS()->getType();
+      if (Ty->isMemberPointerType() && !Ty->isMemberFunctionPointerType())
+        return LV_Valid;
+    }
+    
     if (!BinOp->isAssignmentOp())
       return LV_InvalidExpression;
 

Modified: cfe/trunk/test/SemaCXX/builtin-ptrtomember-overload-1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtin-ptrtomember-overload-1.cpp?rev=83562&r1=83561&r2=83562&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/builtin-ptrtomember-overload-1.cpp (original)
+++ cfe/trunk/test/SemaCXX/builtin-ptrtomember-overload-1.cpp Thu Oct  8 13:00:39 2009
@@ -36,6 +36,7 @@
 
 void foo1(C1 c1, int A::* pmf) {
         int i = c1->*pmf;
+        c1->*pmf = 10;
 }
 
 void foo1(C1 c1, int E::* pmf) {

Modified: cfe/trunk/test/SemaCXX/member-pointer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-pointer.cpp?rev=83562&r1=83561&r2=83562&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/member-pointer.cpp (original)
+++ cfe/trunk/test/SemaCXX/member-pointer.cpp Thu Oct  8 13:00:39 2009
@@ -99,7 +99,7 @@
   int i = phm->*pi;
   (void)&(hm.*pi);
   (void)&(phm->*pi);
-  (void)&((&hm)->*pi); // expected-error {{address expression must be an lvalue or a function designator}}
+  (void)&((&hm)->*pi); 
 
   void (HasMembers::*pf)() = &HasMembers::f;
   (hm.*pf)();





More information about the cfe-commits mailing list