]> granicus.if.org Git - clang/commitdiff
When creating an implicit conversion sequence for a reference of type T from an
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 6 Sep 2013 01:22:42 +0000 (01:22 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 6 Sep 2013 01:22:42 +0000 (01:22 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190115 91177308-0d34-0410-b5e6-96231b3b80d8

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

index a8b0bd27b983a3c1c61264479dbfe5c6801804a2..54b05478108c6af2320301abe6b151ef63b7df53 100644 (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
index 071098440cdb63c38a9df46fd30309c12393e72c..d4098a45b59f9ab740eb6df30cf07502e82dafee 100644 (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()}); }
+}