[llvm-branch-commits] [cfe-branch] r119259 - in /cfe/branches/Apple/whitney: lib/Sema/SemaInit.cpp test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp test/SemaCXX/copy-initialization.cpp

Daniel Dunbar daniel at zuster.org
Mon Nov 15 13:46:36 PST 2010


Author: ddunbar
Date: Mon Nov 15 15:46:36 2010
New Revision: 119259

URL: http://llvm.org/viewvc/llvm-project?rev=119259&view=rev
Log:
Merge r118880:
--
Author: Douglas Gregor <dgregor at apple.com>
Date:   Fri Nov 12 03:34:06 2010 +0000

    When performing initialization of a copy of a temporary object, use
    direct-initialization (rather than copy-initialization) to initialize
    the temporary, allowing explicit constructors. Fixes PR8342.

Modified:
    cfe/branches/Apple/whitney/lib/Sema/SemaInit.cpp
    cfe/branches/Apple/whitney/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp
    cfe/branches/Apple/whitney/test/SemaCXX/copy-initialization.cpp

Modified: cfe/branches/Apple/whitney/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaInit.cpp?rev=119259&r1=119258&r2=119259&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaInit.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaInit.cpp Mon Nov 15 15:46:36 2010
@@ -3391,14 +3391,16 @@
   OverloadCandidateSet CandidateSet(Loc);
   for (llvm::tie(Con, ConEnd) = S.LookupConstructors(Class);
        Con != ConEnd; ++Con) {
-    // Only consider copy constructors and constructor templates.
+    // Only consider copy constructors and constructor templates. Per
+    // C++0x [dcl.init]p16, second bullet to class types, this
+    // initialization is direct-initialization.
     CXXConstructorDecl *Constructor = 0;
 
     if ((Constructor = dyn_cast<CXXConstructorDecl>(*Con))) {
       // Handle copy constructors, only.
       if (!Constructor || Constructor->isInvalidDecl() ||
           !Constructor->isCopyConstructor() ||
-          !Constructor->isConvertingConstructor(/*AllowExplicit=*/false))
+          !Constructor->isConvertingConstructor(/*AllowExplicit=*/true))
         continue;
 
       DeclAccessPair FoundDecl
@@ -3415,7 +3417,7 @@
 
     Constructor = cast<CXXConstructorDecl>(
                                          ConstructorTmpl->getTemplatedDecl());
-    if (!Constructor->isConvertingConstructor(/*AllowExplicit=*/false))
+    if (!Constructor->isConvertingConstructor(/*AllowExplicit=*/true))
       continue;
 
     // FIXME: Do we need to limit this to copy-constructor-like

Modified: cfe/branches/Apple/whitney/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp?rev=119259&r1=119258&r2=119259&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp (original)
+++ cfe/branches/Apple/whitney/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp Mon Nov 15 15:46:36 2010
@@ -53,7 +53,7 @@
 void g5(const X5&);
 
 void test() {
-  g1(X1()); // expected-warning{{no viable constructor copying parameter of type 'X1'; C++98 requires a copy constructor when binding a reference to a temporary [-Wbind-to-temporary-copy]}}
+  g1(X1());
   g2(X2()); // expected-warning{{C++98 requires an accessible copy constructor for class 'X2' when binding a reference to a temporary; was private [-Wbind-to-temporary-copy]}}
   g3(X3()); // expected-warning{{no viable constructor copying parameter of type 'X3'}}
   g4(X4<int>());

Modified: cfe/branches/Apple/whitney/test/SemaCXX/copy-initialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/SemaCXX/copy-initialization.cpp?rev=119259&r1=119258&r2=119259&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/SemaCXX/copy-initialization.cpp (original)
+++ cfe/branches/Apple/whitney/test/SemaCXX/copy-initialization.cpp Mon Nov 15 15:46:36 2010
@@ -10,8 +10,8 @@
 
 void f(Y y, int *ip, float *fp) {
   X x1 = y; // expected-error{{no matching constructor for initialization of 'X'}}
-  X x2 = 0; // expected-error{{no viable constructor copying variable}}
-  X x3 = ip; // expected-error{{no viable constructor copying variable}}
+  X x2 = 0;
+  X x3 = ip;
   X x4 = fp; // expected-error{{no viable conversion}}
   X x2a(0); // expected-error{{call to constructor of 'X' is ambiguous}}
   X x3a(ip);





More information about the llvm-branch-commits mailing list