Index: CodeGen/CGExpr.cpp
===================================================================
--- CodeGen/CGExpr.cpp	(revision 185999)
+++ CodeGen/CGExpr.cpp	(working copy)
@@ -100,9 +100,11 @@
 /// EmitIgnoredExpr - Emit code to compute the specified expression,
 /// ignoring the result.
 void CodeGenFunction::EmitIgnoredExpr(const Expr *E) {
+  ASTContext &Context = getContext();
   if (E->isRValue())
     return (void) EmitAnyExpr(E, AggValueSlot::ignored(), true);
-
+  else if (Context.getLangOpts().CPlusPlus11)
+    return (void) EmitAnyExpr(E, AggValueSlot::ignored(), true);
   // Just emit it as an l-value and drop the result.
   EmitLValue(E);
 }
@@ -1720,6 +1722,12 @@
   return CGF.EmitLValueForField(LV, FD);
 }
 
+inline bool IsLambdaCallOperator(const Decl *D) {
+  if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) 
+    return MD->getParent()->isLambda();
+  return false;
+}
+
 LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
   const NamedDecl *ND = E->getDecl();
   CharUnits Alignment = getContext().getDeclAlign(ND);
@@ -1743,9 +1751,9 @@
   // FIXME: We should be able to assert this for FunctionDecls as well!
   // FIXME: We should be able to assert this for all DeclRefExprs, not just
   // those with a valid source location.
-  assert((ND->isUsed(false) || !isa<VarDecl>(ND) ||
-          !E->getLocation().isValid()) &&
-         "Should not use decl without marking it used!");
+  assert((ND->isUsed(false) || !isa<VarDecl>(ND) || 
+         !E->getLocation().isValid()) || E->isCXX11ConstantExpr(getContext())
+         && "Should not use decl without marking it used!");
 
   if (ND->hasAttr<WeakRefAttr>()) {
     const ValueDecl *VD = cast<ValueDecl>(ND);
@@ -1776,11 +1784,28 @@
         if (const FieldDecl *FD = CapturedStmtInfo->lookup(VD))
           return EmitCapturedFieldLValue(*this, FD,
                                          CapturedStmtInfo->getContextValue());
+      } else if (E->refersToEnclosingLocal() && 
+                  IsLambdaCallOperator(CurCodeDecl))  {
+        // A variable that has not been captured, but refers to an enclosing 
+        // local variable can occur in a lambda context.  It must be usable
+        // in a constant expression context. 
+        assert(VD->isUsableInConstantExpressions(getContext()) &&
+              "Only a constant object can be uncaptured within a lambda.");
+        
+        if (CGM.getCodeGenOpts().MergeAllConstants)
+          V = CGM.getStaticLocalDeclAddress(VD); 
+        else {
+          EmitStaticVarDecl(*VD, VD->isExternallyVisible() ? 
+              llvm::GlobalValue::LinkOnceODRLinkage : 
+                  llvm::GlobalValue::InternalLinkage);
+          V = CGM.getStaticLocalDeclAddress(VD); 
+        }
+        assert(V && "Unable to create a static constant for use in a lambda");
+      } else {
+        assert(isa<BlockDecl>(CurCodeDecl) && E->refersToEnclosingLocal());
+        return MakeAddrLValue(GetAddrOfBlockDecl(VD, isBlockVariable),
+                            T, Alignment);
       }
-
-      assert(isa<BlockDecl>(CurCodeDecl) && E->refersToEnclosingLocal());
-      return MakeAddrLValue(GetAddrOfBlockDecl(VD, isBlockVariable),
-                            T, Alignment);
     }
 
     assert(V && "DeclRefExpr not entered in LocalDeclMap?");
@@ -2396,7 +2421,6 @@
 
 LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
   Expr *BaseExpr = E->getBase();
-
   // If this is s.x, emit s as an lvalue.  If it is s->x, emit s as a scalar.
   LValue BaseLV;
   if (E->isArrow()) {
@@ -2657,10 +2681,13 @@
 
   EmitBlock(contBlock);
 
-  llvm::PHINode *phi = Builder.CreatePHI(lhs.getAddress()->getType(), 2,
-                                         "cond-lvalue");
-  phi->addIncoming(lhs.getAddress(), lhsBlock);
-  phi->addIncoming(rhs.getAddress(), rhsBlock);
+  llvm::Value *LHSVal = lhs.getAddress();
+  llvm::Value *RHSVal = rhs.getAddress();
+  llvm::PHINode *phi = Builder.CreatePHI(LHSVal->getType(), 2,
+    "cond-lvalue");
+  phi->addIncoming(LHSVal, lhsBlock);
+  phi->addIncoming(RHSVal, rhsBlock);
+
   return MakeAddrLValue(phi, expr->getType());
 }
 
@@ -3132,11 +3159,67 @@
 LValue CodeGenFunction::
 EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E) {
   llvm::Value *BaseV;
-  if (E->getOpcode() == BO_PtrMemI)
-    BaseV = EmitScalarExpr(E->getLHS());
-  else
-    BaseV = EmitLValue(E->getLHS()).getAddress();
+  LValue BaseLV;
+  Expr *PointerToMem = E->getRHS();
+  Expr *ObjExpr = E->getLHS();
+  ASTContext &Context = getContext();
 
+
+  if (E->getOpcode() == BO_PtrMemI) {
+    BaseV = EmitScalarExpr(ObjExpr);
+    QualType PtrTy = ObjExpr->getType()->getPointeeType();
+    EmitTypeCheck(CodeGenFunction::TCK_MemberAccess, 
+      E->getExprLoc(), BaseV, PtrTy);
+    BaseLV = MakeNaturalAlignAddrLValue(BaseV, PtrTy);
+  }
+  else {
+    BaseLV = EmitLValue(E->getLHS());
+    BaseV = BaseLV.getAddress();
+  }
+
+  Expr::EvalResult ConstExprEvalResult;
+  // If the pointer to data member is a constant, emit the field decl
+  // access directly.  
+  if (PointerToMem->EvaluateAsRValue(ConstExprEvalResult, Context)) {
+    const ValueDecl *VD;
+    if (ConstExprEvalResult.Val.isMemberPointer() && 
+          (VD = ConstExprEvalResult.Val.getMemberPointerDecl())) {
+      
+      if (const FieldDecl *Field = dyn_cast<const FieldDecl>(VD)) {
+        LValue LV = EmitLValueForField(BaseLV, Field);
+        //CGF.setObjCGCLValueClass(CGF.getContext(), E, LV);
+        return LV; //EmitLoadOfLValue(LV);
+      }
+      assert(false && "Only field decls can be emitted as scalars!");
+      // FVQUESTION: Do we need to handle the additional cases?
+      if (const FunctionDecl *FD = dyn_cast<const FunctionDecl>(VD)) {
+        // If RS Oks this, we should move EmitFunctionDeclLValue 
+        // from CGExpr.cpp into CGF and call it from here, instead of 
+        // duplicating functionality.
+        llvm::Value *V = CGM.GetAddrOfFunction(FD);
+        if (!FD->hasPrototype()) {
+          if (const FunctionProtoType *Proto =
+            FD->getType()->getAs<FunctionProtoType>()) {
+              // Ugly case: for a K&R-style definition, the type of 
+              // the definition isn't the same as the type of a use.  
+              // Correct for this with a bitcast.
+              QualType NoProtoType =
+                Context.getFunctionNoProtoType(
+                                                Proto->getResultType());
+              NoProtoType = Context.getPointerType(
+                                                NoProtoType);
+              V = Builder.CreateBitCast(V, ConvertType(NoProtoType));
+          }
+        }
+        CharUnits Alignment = Context.getDeclAlign(FD);
+        return MakeAddrLValue(V, E->getType(), Alignment);
+      }
+      //if (const VarDecl *VD = dyn_cast<const VarDecl>(VD))
+      //  return EmitGlobalVarDeclLValue(*this, E, VD);
+      
+    }
+  }
+  
   llvm::Value *OffsetV = EmitScalarExpr(E->getRHS());
 
   const MemberPointerType *MPT
Index: CodeGen/CGExprAgg.cpp
===================================================================
--- CodeGen/CGExprAgg.cpp	(revision 185999)
+++ CodeGen/CGExprAgg.cpp	(working copy)
@@ -137,7 +137,20 @@
     EmitAggLoadOfLValue(E);
   }
 
-  void VisitMemberExpr(MemberExpr *ME) { EmitAggLoadOfLValue(ME); }
+  void VisitMemberExpr(MemberExpr *ME) { 
+    ASTContext &Context = CGF.getContext(); 
+    APValue ConstexprResult;
+    if (Context.getLangOpts().CPlusPlus11 && 
+          ME->isCXX11ConstantExpr(Context, &ConstexprResult)) {
+      llvm::Constant *C = CGF.CGM.EmitConstantValue(ConstexprResult, 
+                                                              ME->getType());
+      // FVQUESTION: Is the check for volatile qualified correct?
+      RValue RV = RValue::getAggregate(C, ME->getType().isVolatileQualified());
+      EmitFinalDestCopy(ME->getType(), RV);  
+    }
+    else
+      EmitAggLoadOfLValue(ME); 
+  }
   void VisitUnaryDeref(UnaryOperator *E) { EmitAggLoadOfLValue(E); }
   void VisitStringLiteral(StringLiteral *E) { EmitAggLoadOfLValue(E); }
   void VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
@@ -793,8 +806,20 @@
 
 void AggExprEmitter::VisitPointerToDataMemberBinaryOperator(
                                                     const BinaryOperator *E) {
-  LValue LV = CGF.EmitPointerToDataMemberBinaryExpr(E);
-  EmitFinalDestCopy(E->getType(), LV);
+  ASTContext &Context = CGF.getContext(); 
+  APValue ConstexprResult;
+  if (Context.getLangOpts().CPlusPlus11 && 
+        E->isCXX11ConstantExpr(Context, &ConstexprResult)) {
+    llvm::Constant *C = CGF.CGM.EmitConstantValue(ConstexprResult, 
+                                                            E->getType());
+    // FVQUESTION: Is the check for volatile qualified correct?
+    RValue RV = RValue::getAggregate(C, E->getType().isVolatileQualified());
+    EmitFinalDestCopy(E->getType(), RV);  
+  }
+  else {
+    LValue LV = CGF.EmitPointerToDataMemberBinaryExpr(E);
+    EmitFinalDestCopy(E->getType(), LV);
+  }
 }
 
 /// Is the value of the given expression possibly a reference to or
Index: CodeGen/CGExprScalar.cpp
===================================================================
--- CodeGen/CGExprScalar.cpp	(revision 185999)
+++ CodeGen/CGExprScalar.cpp	(working copy)
@@ -499,8 +499,73 @@
   Value *VisitBinLOr        (const BinaryOperator *E);
   Value *VisitBinComma      (const BinaryOperator *E);
 
-  Value *VisitBinPtrMemD(const Expr *E) { return EmitLoadOfLValue(E); }
-  Value *VisitBinPtrMemI(const Expr *E) { return EmitLoadOfLValue(E); }
+  Value *VisitBinPtrMemD(const BinaryOperator *E, bool IsArrow = false) { 
+    ASTContext &Context = CGF.getContext();
+    APValue Result;
+    const Expr *PointerToMem = E->getRHS();
+    const Expr *ObjExpr = E->getLHS();
+    Expr::EvalResult ConstExprEvalResult;
+    // Emit the pointer to data member as a constant if we can.
+    if (Context.getLangOpts().CPlusPlus11 && 
+          E->isCXX11ConstantExpr(Context, &Result)) {
+       llvm::Constant *Val =
+            CGF.CGM.EmitConstantValue(Result, E->getType());
+       assert(Val && "Could not emit constant for a pointer to member expr!");
+       return Val;
+    } else if (PointerToMem->EvaluateAsRValue(ConstExprEvalResult, Context)) {
+      const ValueDecl *VD;
+      if (ConstExprEvalResult.Val.isMemberPointer() && 
+            (VD = ConstExprEvalResult.Val.getMemberPointerDecl())) {
+        LValue BaseLV;
+        if (!IsArrow) 
+          BaseLV = CGF.EmitCheckedLValue(ObjExpr, 
+                                CodeGenFunction::TCK_MemberAccess);
+        else {
+          llvm::Value *Ptr = CGF.EmitScalarExpr(ObjExpr);
+          QualType PtrTy = ObjExpr->getType()->getPointeeType();
+          CGF.EmitTypeCheck(CodeGenFunction::TCK_MemberAccess, 
+                                      E->getExprLoc(), Ptr, PtrTy);
+          BaseLV = CGF.MakeNaturalAlignAddrLValue(Ptr, PtrTy);
+        }
+        if (const FieldDecl *Field = dyn_cast<const FieldDecl>(VD)) {
+          LValue LV = CGF.EmitLValueForField(BaseLV, Field);
+          //CGF.setObjCGCLValueClass(CGF.getContext(), E, LV);
+          return EmitLoadOfLValue(LV);
+        }
+        assert(false && "Only field decls can be emitted as scalars!");
+        // FVQUESTION: Do we need to handle the additional cases?
+        /*
+        if (const FunctionDecl *FD = dyn_cast<const FunctionDecl>(VD)) {
+          // If RS Oks this, we should move EmitFunctionDeclLValue 
+          // from CGExpr.cpp into CGF and call it from here, instead of 
+          // duplicating functionality.
+          llvm::Value *V = CGF.CGM.GetAddrOfFunction(FD);
+          if (!FD->hasPrototype()) {
+            if (const FunctionProtoType *Proto =
+              FD->getType()->getAs<FunctionProtoType>()) {
+                // Ugly case: for a K&R-style definition, the type of 
+                // the definition isn't the same as the type of a use.  
+                // Correct for this with a bitcast.
+                QualType NoProtoType =
+                  CGF.getContext().getFunctionNoProtoType(
+                                                  Proto->getResultType());
+                NoProtoType = CGF.getContext().getPointerType(
+                                                  NoProtoType);
+                V = CGF.Builder.CreateBitCast(V, CGF.ConvertType(NoProtoType));
+            }
+          }
+          CharUnits Alignment = CGF.getContext().getDeclAlign(FD);
+          return EmitLoadOfLValue(CGF.MakeAddrLValue(V, E->getType(), Alignment));
+        }
+        if (const VarDecl *VD = dyn_cast<const VarDecl>(VD))
+          return EmitGlobalVarDeclLValue(*this, E, VD);
+        */
+      }  
+    }
+    return EmitLoadOfLValue(E); 
+  }
+  Value *VisitBinPtrMemI(const BinaryOperator *E) { return VisitBinPtrMemD(E, 
+                                                           /*IsArrow*/ true); }
 
   // Other Operators.
   Value *VisitBlockExpr(const BlockExpr *BE);
@@ -984,11 +1049,17 @@
 }
 Value *ScalarExprEmitter::VisitMemberExpr(MemberExpr *E) {
   llvm::APSInt Value;
+  Expr *ObjExpr = E->getBase();
+  ASTContext &Context = CGF.getContext();
   if (E->EvaluateAsInt(Value, CGF.getContext(), Expr::SE_AllowSideEffects)) {
+    APValue ConstExprResult;
     if (E->isArrow())
-      CGF.EmitScalarExpr(E->getBase());
-    else
-      EmitLValue(E->getBase());
+      CGF.EmitScalarExpr(ObjExpr);
+    else if (Context.getLangOpts().CPlusPlus11 
+          && ObjExpr->isCXX11ConstantExpr(Context, &ConstExprResult))
+      CGF.CGM.EmitConstantValue(ConstExprResult, ObjExpr->getType());
+    else  
+      EmitLValue(ObjExpr);
     return Builder.getInt(Value);
   }
 
Index: Sema/SemaExpr.cpp
===================================================================
--- Sema/SemaExpr.cpp	(revision 185999)
+++ Sema/SemaExpr.cpp	(working copy)
@@ -11560,13 +11560,71 @@
   Var->setUsed(true);
 }
 
+
+namespace {
+struct PotentialResultsSetFinder : 
+  ConstStmtVisitor<PotentialResultsSetFinder> {
+  llvm::SmallPtrSet<Expr*, 2> &MaybeODRUseExprs;
+  ASTContext &Context;
+  PotentialResultsSetFinder(
+      llvm::SmallPtrSet<Expr*, 2>& MaybeODRUseExprs, ASTContext &Context) :
+          MaybeODRUseExprs(MaybeODRUseExprs), Context(Context) { }
+  // C++1y DR712 3.2 para 2
+  // The set of potential results of an expression e is defined as follows:
+
+  // -- If e is an id-expression (5.1.1), the set contains only e.
+  void VisitDeclRefExpr(const DeclRefExpr *E) {
+    MaybeODRUseExprs.erase(const_cast<DeclRefExpr*>(E));
+  }
+  //  -- If e is a class member access expression (5.2.5), the set contains
+  //     the potential results of the object expression.
+  void VisitMemberExpr(const MemberExpr *E) {
+    Expr *ObjectExpression = E->getBase();
+    Visit(ObjectExpression);
+  }
+  // -- If e is a pointer-to-member expression (5.5) whose second operand 
+  //    is a constant expression, the set contains the potential results of 
+  //    the object expression.  
+  void VisitBinPtrMemD(const BinaryOperator *E) {
+    Expr *SecondOperand = E->getRHS();
+    if (SecondOperand->isCXX11ConstantExpr(Context))
+      Visit(E->getLHS());
+  }
+  void VisitBinPtrMemI(const BinaryOperator *E) {
+    VisitBinPtrMemD(E);
+  }
+    
+  // -- If e has the form (e1), the set contains the potential results of e1.
+  void VisitParenExpr(const ParenExpr *E) {
+    Visit(E->getSubExpr());
+  }
+  // -- If e is a glvalue conditional expression (5.16), the set is the 
+  //    union of the sets of potential results of the second and third 
+  //    operands.
+  void VisitConditionalOperator(const ConditionalOperator *CO) {
+    if (CO->isGLValue()) {
+      Visit(CO->getTrueExpr());
+      Visit(CO->getFalseExpr());
+    }
+  }
+
+  // -- If e is a comma expression (5.18), the set contains the potential 
+  //    results of the right operand.
+  void VisitBinComma(const BinaryOperator *E) {
+    Visit(E->getRHS());
+  }
+  // -- Otherwise, the set is empty.
+  void VisitStmt(const Stmt *) { return; }
+};
+}
+
 void Sema::UpdateMarkingForLValueToRValue(Expr *E) {
   // Per C++11 [basic.def.odr], a variable is odr-used "unless it is 
   // an object that satisfies the requirements for appearing in a
   // constant expression (5.19) and the lvalue-to-rvalue conversion (4.1)
   // is immediately applied."  This function handles the lvalue-to-rvalue
   // conversion part.
-  MaybeODRUseExprs.erase(E->IgnoreParens());
+  PotentialResultsSetFinder(MaybeODRUseExprs, Context).Visit(E);
 }
 
 ExprResult Sema::ActOnConstantExpression(ExprResult Res) {
Index: Sema/SemaExprCXX.cpp
===================================================================
--- Sema/SemaExprCXX.cpp	(revision 185999)
+++ Sema/SemaExprCXX.cpp	(working copy)
@@ -5589,9 +5589,9 @@
 
   if (getLangOpts().CPlusPlus)  {
     // The C++11 standard defines the notion of a discarded-value expression;
-    // normally, we don't need to do anything to handle it, but if it is a
-    // volatile lvalue with a special form, we perform an lvalue-to-rvalue
-    // conversion.
+    // normally, we don't need to do any additional conversions to handle it, 
+    // but if it is a volatile lvalue with a special form, we perform an 
+    // lvalue-to-rvalue conversion. 
     if (getLangOpts().CPlusPlus11 && E->isGLValue() &&
         E->getType().isVolatileQualified() &&
         IsSpecialDiscardedValue(E)) {
@@ -5599,6 +5599,11 @@
       if (Res.isInvalid())
         return Owned(E);
       E = Res.take();
+    } else if (getLangOpts().CPlusPlus11 && E->isGLValue()) {
+      // Even if we do not perform an lvalue-to-rvalue conversion, 
+      // we pretend that one was performed when checking for odr-uses
+      // of variables.
+      UpdateMarkingForLValueToRValue(E);
     }
     return Owned(E);
   }
