[cfe-commits] r151716 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/SemaCXX/cxx0x-initializer-constructor.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Wed Feb 29 04:47:43 PST 2012


Author: cornedbee
Date: Wed Feb 29 06:47:43 2012
New Revision: 151716

URL: http://llvm.org/viewvc/llvm-project?rev=151716&view=rev
Log:
Tentatively fix PR12117. The test case from the bug now passes, and all existing tests still pass, but there may still be corner cases.

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/SemaCXX/cxx0x-initializer-constructor.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=151716&r1=151715&r2=151716&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Feb 29 06:47:43 2012
@@ -2795,7 +2795,7 @@
                            DeclContext::lookup_iterator ConEnd,
                            OverloadCandidateSet::iterator &Best,
                            bool CopyInitializing, bool AllowExplicit,
-                           bool OnlyListConstructors) {
+                           bool OnlyListConstructors, bool InitListSyntax) {
   CandidateSet.clear();
 
   for (; Con != ConEnd; ++Con) {
@@ -2813,9 +2813,10 @@
       Constructor = cast<CXXConstructorDecl>(D);
 
       // If we're performing copy initialization using a copy constructor, we
-      // suppress user-defined conversions on the arguments.
-      // FIXME: Move constructors?
-      if (CopyInitializing && Constructor->isCopyConstructor())
+      // suppress user-defined conversions on the arguments. We do the same for
+      // move constructors.
+      if ((CopyInitializing || (InitListSyntax && NumArgs == 1)) &&
+          Constructor->isCopyOrMoveConstructor())
         SuppressUserConversions = true;
     }
 
@@ -2825,8 +2826,8 @@
       if (ConstructorTmpl)
         S.AddTemplateOverloadCandidate(ConstructorTmpl, FoundDecl,
                                        /*ExplicitArgs*/ 0,
-                                       llvm::makeArrayRef(Args, NumArgs), CandidateSet,
-                                       SuppressUserConversions);
+                                       llvm::makeArrayRef(Args, NumArgs),
+                                       CandidateSet, SuppressUserConversions);
       else {
         // C++ [over.match.copy]p1:
         //   - When initializing a temporary to be bound to the first parameter 
@@ -2919,7 +2920,8 @@
     Result = ResolveConstructorOverload(S, Kind.getLocation(), Args, NumArgs,
                                         CandidateSet, ConStart, ConEnd, Best,
                                         CopyInitialization, AllowExplicit,
-                                        /*OnlyListConstructor=*/true);
+                                        /*OnlyListConstructor=*/true,
+                                        InitListSyntax);
 
     // Time to unwrap the init list.
     InitListExpr *ILE = cast<InitListExpr>(Args[0]);
@@ -2937,7 +2939,8 @@
     Result = ResolveConstructorOverload(S, Kind.getLocation(), Args, NumArgs,
                                         CandidateSet, ConStart, ConEnd, Best,
                                         CopyInitialization, AllowExplicit,
-                                        /*OnlyListConstructors=*/false);
+                                        /*OnlyListConstructors=*/false,
+                                        InitListSyntax);
   }
   if (Result) {
     Sequence.SetOverloadFailure(InitListSyntax ?

Modified: cfe/trunk/test/SemaCXX/cxx0x-initializer-constructor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-initializer-constructor.cpp?rev=151716&r1=151715&r2=151716&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-initializer-constructor.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-initializer-constructor.cpp Wed Feb 29 06:47:43 2012
@@ -212,3 +212,9 @@
   }
 
 }
+
+namespace PR12117 {
+  struct A { A(int); }; 
+  struct B { B(A); } b{{0}};
+  struct C { C(int); } c{0};
+}





More information about the cfe-commits mailing list