@@ -3465,8 +3465,9 @@ compareStandardConversionSubsets(ASTContext &Context,
3465
3465
3466
3466
/// \brief Determine whether one of the given reference bindings is better
3467
3467
/// than the other based on what kind of bindings they are.
3468
- static bool isBetterReferenceBindingKind(const StandardConversionSequence &SCS1,
3469
- const StandardConversionSequence &SCS2) {
3468
+ static bool
3469
+ isBetterReferenceBindingKind(const StandardConversionSequence &SCS1,
3470
+ const StandardConversionSequence &SCS2) {
3470
3471
// C++0x [over.ics.rank]p3b4:
3471
3472
// -- S1 and S2 are reference bindings (8.5.3) and neither refers to an
3472
3473
// implicit object parameter of a non-static member function declared
@@ -3487,7 +3488,7 @@ static bool isBetterReferenceBindingKind(const StandardConversionSequence &SCS1,
3487
3488
return (!SCS1.IsLvalueReference && SCS1.BindsToRvalue &&
3488
3489
SCS2.IsLvalueReference) ||
3489
3490
(SCS1.IsLvalueReference && SCS1.BindsToFunctionLvalue &&
3490
- !SCS2.IsLvalueReference);
3491
+ !SCS2.IsLvalueReference && SCS2.BindsToFunctionLvalue );
3491
3492
}
3492
3493
3493
3494
/// CompareStandardConversionSequences - Compare two standard
@@ -4372,6 +4373,10 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
4372
4373
return ICS;
4373
4374
}
4374
4375
4376
+ // A temporary of function type cannot be created; don't even try.
4377
+ if (T1->isFunctionType())
4378
+ return ICS;
4379
+
4375
4380
// -- Otherwise, a temporary of type "cv1 T1" is created and
4376
4381
// initialized from the initializer expression using the
4377
4382
// rules for a non-reference copy initialization (8.5). The
@@ -4433,28 +4438,34 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
4433
4438
if (ICS.isStandard()) {
4434
4439
ICS.Standard.ReferenceBinding = true;
4435
4440
ICS.Standard.IsLvalueReference = !isRValRef;
4436
- ICS.Standard.BindsToFunctionLvalue = T2->isFunctionType() ;
4441
+ ICS.Standard.BindsToFunctionLvalue = false ;
4437
4442
ICS.Standard.BindsToRvalue = true;
4438
4443
ICS.Standard.BindsImplicitObjectArgumentWithoutRefQualifier = false;
4439
4444
ICS.Standard.ObjCLifetimeConversionBinding = false;
4440
4445
} else if (ICS.isUserDefined()) {
4441
- // Don't allow rvalue references to bind to lvalues.
4442
- if (DeclType->isRValueReferenceType()) {
4443
- if (const ReferenceType *RefType =
4444
- ICS.UserDefined.ConversionFunction->getReturnType()
4445
- ->getAs<LValueReferenceType>()) {
4446
- if (!RefType->getPointeeType()->isFunctionType()) {
4447
- ICS.setBad(BadConversionSequence::lvalue_ref_to_rvalue, Init,
4448
- DeclType);
4449
- return ICS;
4450
- }
4451
- }
4446
+ const ReferenceType *LValRefType =
4447
+ ICS.UserDefined.ConversionFunction->getReturnType()
4448
+ ->getAs<LValueReferenceType>();
4449
+
4450
+ // C++ [over.ics.ref]p3:
4451
+ // Except for an implicit object parameter, for which see 13.3.1, a
4452
+ // standard conversion sequence cannot be formed if it requires [...]
4453
+ // binding an rvalue reference to an lvalue other than a function
4454
+ // lvalue.
4455
+ // Note that the function case is not possible here.
4456
+ if (DeclType->isRValueReferenceType() && LValRefType) {
4457
+ // FIXME: This is the wrong BadConversionSequence. The problem is binding
4458
+ // an rvalue reference to a (non-function) lvalue, not binding an lvalue
4459
+ // reference to an rvalue!
4460
+ ICS.setBad(BadConversionSequence::lvalue_ref_to_rvalue, Init, DeclType);
4461
+ return ICS;
4452
4462
}
4463
+
4453
4464
ICS.UserDefined.Before.setAsIdentityConversion();
4454
4465
ICS.UserDefined.After.ReferenceBinding = true;
4455
4466
ICS.UserDefined.After.IsLvalueReference = !isRValRef;
4456
- ICS.UserDefined.After.BindsToFunctionLvalue = T2->isFunctionType() ;
4457
- ICS.UserDefined.After.BindsToRvalue = true ;
4467
+ ICS.UserDefined.After.BindsToFunctionLvalue = false ;
4468
+ ICS.UserDefined.After.BindsToRvalue = !LValRefType ;
4458
4469
ICS.UserDefined.After.BindsImplicitObjectArgumentWithoutRefQualifier = false;
4459
4470
ICS.UserDefined.After.ObjCLifetimeConversionBinding = false;
4460
4471
}
0 commit comments