]> granicus.if.org Git - clang/commitdiff
Allow a conversion from the empty initializer list {} to an
authorDouglas Gregor <dgregor@apple.com>
Wed, 4 Apr 2012 23:09:20 +0000 (23:09 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 4 Apr 2012 23:09:20 +0000 (23:09 +0000)
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

lib/Sema/SemaOverload.cpp
test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp

index 7afa39f3f3b0b099e06ca8312a1f8c43e5e3e6d5..e4c6fdfb59c2f2e870e62d267e96011993332739 100644 (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;
index 3437849f931b02718ec433ade0203590ec3f2ff4..7384309f97dabe91d9e7c8428d42a9da12eafa13 100644 (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);
+}