When creating an implicit conversion sequence for a reference of type T from an

initializer list containing a single element of type T, be sure to mark the
sequence as a list conversion sequence so that it is known to be worse than an
implicit conversion sequence that initializes a std::initializer_list object.

llvm-svn: 190115
This commit is contained in:
Richard Smith 2013-09-06 01:22:42 +00:00
parent bc8c734fa7
commit 4d2bbd78ff
2 changed files with 19 additions and 5 deletions

View File

@ -509,6 +509,11 @@ void UserDefinedConversionSequence::DebugPrint() const {
/// error. Useful for debugging overloading issues.
void ImplicitConversionSequence::DebugPrint() const {
raw_ostream &OS = llvm::errs();
if (isListInitializationSequence()) {
OS << "List-initialization sequence: ";
if (isStdInitializerListElement())
OS << "Worst std::initializer_list element conversion: ";
}
switch (ConversionKind) {
case StandardConversion:
OS << "Standard conversion: ";
@ -4524,11 +4529,13 @@ TryListConversion(Sema &S, InitListExpr *From, QualType ToType,
= S.CompareReferenceRelationship(From->getLocStart(), T1, T2, dummy1,
dummy2, dummy3);
if (RefRelationship >= Sema::Ref_Related)
return TryReferenceInit(S, Init, ToType,
/*FIXME:*/From->getLocStart(),
SuppressUserConversions,
/*AllowExplicit=*/false);
if (RefRelationship >= Sema::Ref_Related) {
Result = TryReferenceInit(S, Init, ToType, /*FIXME*/From->getLocStart(),
SuppressUserConversions,
/*AllowExplicit=*/false);
Result.setListInitializationSequence();
return Result;
}
}
// Otherwise, we bind the reference to a temporary created from the

View File

@ -218,3 +218,10 @@ namespace deleted_copy {
std::initializer_list<X> x{1}; // expected-error {{invokes deleted constructor}}
}
namespace RefVersusInitList {
struct S {};
void f(const S &) = delete;
void f(std::initializer_list<S>);
void g(S s) { f({S()}); }
}