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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154065 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Douglas Gregor 2012-04-04 23:09:20 +00:00
Родитель 3953911de1
Коммит 5b4bf13761
2 изменённых файлов: 19 добавлений и 0 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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);
}