[cfe-commits] r63554 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/SemaCXX/user-defined-conversions.cpp

Douglas Gregor dgregor at apple.com
Mon Feb 2 14:11:11 PST 2009


Author: dgregor
Date: Mon Feb  2 16:11:10 2009
New Revision: 63554

URL: http://llvm.org/viewvc/llvm-project?rev=63554&view=rev
Log:
Steve set me straight on this one. GCC was right, EDG was wrong: the
direct-initialization following a user-defined conversion can select
any constructor; it just can't employ any user-defined
conversions. So we ban those conversions and classify the constructor
call based on the relationship between the "from" and "to" types in
the conversion.


Modified:
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/SemaCXX/user-defined-conversions.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=63554&r1=63553&r2=63554&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Mon Feb  2 16:11:10 2009
@@ -383,7 +383,10 @@
     //   called for those cases.
     if (CXXConstructorDecl *Constructor 
           = dyn_cast<CXXConstructorDecl>(ICS.UserDefined.ConversionFunction)) {
-      if (Constructor->isCopyConstructor(Context)) {
+      QualType FromCanon 
+        = Context.getCanonicalType(From->getType().getUnqualifiedType());
+      QualType ToCanon = Context.getCanonicalType(ToType).getUnqualifiedType();
+      if (FromCanon == ToCanon || IsDerivedFrom(FromCanon, ToCanon)) {
         // Turn this into a "standard" conversion sequence, so that it
         // gets ranked with standard conversion sequences.
         ICS.ConversionKind = ImplicitConversionSequence::StandardConversion;
@@ -391,8 +394,7 @@
         ICS.Standard.FromTypePtr = From->getType().getAsOpaquePtr();
         ICS.Standard.ToTypePtr = ToType.getAsOpaquePtr();
         ICS.Standard.CopyConstructor = Constructor;
-        if (IsDerivedFrom(From->getType().getUnqualifiedType(),
-                          ToType.getUnqualifiedType()))
+        if (ToCanon != FromCanon)
           ICS.Standard.Second = ICK_Derived_To_Base;
       }
     }

Modified: cfe/trunk/test/SemaCXX/user-defined-conversions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/user-defined-conversions.cpp?rev=63554&r1=63553&r2=63554&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/user-defined-conversions.cpp (original)
+++ cfe/trunk/test/SemaCXX/user-defined-conversions.cpp Mon Feb  2 16:11:10 2009
@@ -65,5 +65,5 @@
   Base b2(ctb);
   Base b3 = ctd;
   Base b4(ctd);
-  Base b5 = ctfd; // expected-error{{cannot initialize 'b5' with an lvalue of type 'struct ConvertibleToFunkyDerived'}}
+  Base b5 = ctfd;
 }





More information about the cfe-commits mailing list