PR45521: Preserve the value kind when performing a standard conversion

sequence on a glvalue expression.

If the sequence is supposed to perform an lvalue-to-rvalue conversion,
then one will be specified as the first conversion in the sequence.
Otherwise, one should not be invented.
This commit is contained in:
Richard Smith 2020-07-07 18:25:57 -07:00
parent 74145d5841
commit 065fc1eafe
3 changed files with 10 additions and 8 deletions

View File

@ -4203,8 +4203,8 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
break;
case ICK_Compatible_Conversion:
From = ImpCastExprToType(From, ToType, CK_NoOp,
VK_RValue, /*BasePath=*/nullptr, CCK).get();
From = ImpCastExprToType(From, ToType, CK_NoOp, From->getValueKind(),
/*BasePath=*/nullptr, CCK).get();
break;
case ICK_Writeback_Conversion:
@ -4441,11 +4441,7 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
break;
case ICK_Qualification: {
// The qualification keeps the category of the inner expression, unless the
// target type isn't a reference.
ExprValueKind VK =
ToType->isReferenceType() ? From->getValueKind() : VK_RValue;
ExprValueKind VK = From->getValueKind();
CastKind CK = CK_NoOp;
if (ToType->isReferenceType() &&

View File

@ -4709,7 +4709,7 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
Sema::ReferenceConversions::NestedQualification)
? ICK_Qualification
: ICK_Identity;
ICS.Standard.FromTypePtr = T2.getAsOpaquePtr();
ICS.Standard.setFromType(T2);
ICS.Standard.setToType(0, T2);
ICS.Standard.setToType(1, T1);
ICS.Standard.setToType(2, T1);

View File

@ -201,3 +201,9 @@ namespace RefCollapseTypePrinting {
template void add_rref<const int&>(); // expected-note {{instantiation of}}
template void add_rref<const int&&>(); // expected-note {{instantiation of}}
}
namespace PR45521 {
struct a { template<class b> a(const b * const&); };
int *d;
const a &r = d;
}