From 0f5c1c01273dabe68a63127ee78d004310594b16 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 4 Apr 2012 23:09:20 +0000 Subject: [PATCH] Allow a conversion from the empty initializer list {} to an std::initializer_list so long as is known. This conversion has identity rank. llvm-svn: 154065 --- clang/lib/Sema/SemaOverload.cpp | 10 ++++++++++ .../SemaCXX/cxx0x-initializer-stdinitializerlist.cpp | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 7afa39f3f3b0..e4c6fdfb59c2 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -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; diff --git a/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp b/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp index 3437849f931b..7384309f97da 100644 --- a/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp +++ b/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp @@ -166,3 +166,12 @@ namespace Decay { for( auto s : {"A", "BB", "CCC", "DDD"}) { } } } + +namespace PR12436 { + struct X { + template + X(std::initializer_list, T); + }; + + X x({}, 17); +}