Author: rsmith Date: Mon Apr 25 14:30:37 2016 New Revision: 267454 URL: http://llvm.org/viewvc/llvm-project?rev=267454&view=rev Log: Implement support for conditional between xvalues of reference-compatible types. Patch by Erik Pilkington!
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp cfe/trunk/test/SemaCXX/conditional-expr.cpp Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=267454&r1=267453&r2=267454&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Apr 25 14:30:37 2016 @@ -4795,7 +4795,7 @@ QualType Sema::CheckPointerToMemberOpera return Result; } -/// \brief Try to convert a type to another according to C++0x 5.16p3. +/// \brief Try to convert a type to another according to C++11 5.16p3. /// /// This is part of the parameter validation for the ? operator. If either /// value operand is a class type, the two operands are attempted to be @@ -4811,17 +4811,21 @@ static bool TryClassUnification(Sema &Se InitializationKind Kind = InitializationKind::CreateCopy(To->getLocStart(), SourceLocation()); - // C++0x 5.16p3 + // C++11 5.16p3 // The process for determining whether an operand expression E1 of type T1 // can be converted to match an operand expression E2 of type T2 is defined // as follows: - // -- If E2 is an lvalue: - bool ToIsLvalue = To->isLValue(); - if (ToIsLvalue) { - // E1 can be converted to match E2 if E1 can be implicitly converted to - // type "lvalue reference to T2", subject to the constraint that in the - // conversion the reference must bind directly to E1. - QualType T = Self.Context.getLValueReferenceType(ToType); + // -- If E2 is an lvalue: E1 can be converted to match E2 if E1 can be + // implicitly converted to type "lvalue reference to T2", subject to the + // constraint that in the conversion the reference must bind directly to + // an lvalue. + // -- If E2 is an xvalue: E1 can be converted to match E2 if E1 can be + // implicitly conveted to the type "rvalue reference to R2", subject to + // the constraint that the reference must bind directly. + if (To->isLValue() || To->isXValue()) { + QualType T = To->isLValue() ? Self.Context.getLValueReferenceType(ToType) + : Self.Context.getRValueReferenceType(ToType); + InitializedEntity Entity = InitializedEntity::InitializeTemporary(T); InitializationSequence InitSeq(Self, Entity, Kind, From); Modified: cfe/trunk/test/SemaCXX/conditional-expr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/conditional-expr.cpp?rev=267454&r1=267453&r2=267454&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/conditional-expr.cpp (original) +++ cfe/trunk/test/SemaCXX/conditional-expr.cpp Mon Apr 25 14:30:37 2016 @@ -384,3 +384,12 @@ namespace PR17052 { int &test() { return b_ ? i_ : throw 1; } }; } + +namespace PR26448 { +struct Base {}; +struct Derived : Base {}; +Base b; +Derived d; +typedef decltype(true ? static_cast<Base&&>(b) : static_cast<Derived&&>(d)) x; +typedef Base &&x; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits