Allow a conversion from the empty initializer list {} to an

std::initializer_list<T> so long as <T> is known. This conversion has
identity rank.

llvm-svn: 154065
This commit is contained in:
Douglas Gregor 2012-04-04 23:09:20 +00:00
parent bea0d04f8c
commit 0f5c1c0127
2 changed files with 19 additions and 0 deletions

View File

@ -4301,6 +4301,16 @@ TryListConversion(Sema &S, InitListExpr *From, QualType ToType,
ImplicitConversionSequence::Worse)
Result = ICS;
}
// For an empty list, we won't have computed any conversion sequence.
// Introduce the identity conversion sequence.
if (From->getNumInits() == 0) {
Result.setStandard();
Result.Standard.setAsIdentityConversion();
Result.Standard.setFromType(ToType);
Result.Standard.setAllToTypes(ToType);
}
Result.setListInitializationSequence();
Result.setStdInitializerListElement(toStdInitializerList);
return Result;

View File

@ -166,3 +166,12 @@ namespace Decay {
for( auto s : {"A", "BB", "CCC", "DDD"}) { }
}
}
namespace PR12436 {
struct X {
template<typename T>
X(std::initializer_list<int>, T);
};
X x({}, 17);
}