[cfe-commits] r91861 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/CodeGenCXX/PR5834-constructor-conversion.cpp

Douglas Gregor dgregor at apple.com
Mon Dec 21 16:21:20 PST 2009


Author: dgregor
Date: Mon Dec 21 18:21:20 2009
New Revision: 91861

URL: http://llvm.org/viewvc/llvm-project?rev=91861&view=rev
Log:
When converting from a type to itself or one of its base classes via a
constructor call, the conversion is only a standard conversion
sequence if that constructor is a copy constructor. This fixes PR5834
in a semi-lame way, because the "real" fix will be to move over to
InitializationSequence. That will happen "soonish", but not now.

Added:
    cfe/trunk/test/CodeGenCXX/PR5834-constructor-conversion.cpp
Modified:
    cfe/trunk/lib/Sema/SemaOverload.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Mon Dec 21 18:21:20 2009
@@ -451,7 +451,8 @@
       QualType FromCanon
         = Context.getCanonicalType(From->getType().getUnqualifiedType());
       QualType ToCanon = Context.getCanonicalType(ToType).getUnqualifiedType();
-      if (FromCanon == ToCanon || IsDerivedFrom(FromCanon, ToCanon)) {
+      if (Constructor->isCopyConstructor(Context) &&
+          (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;

Added: cfe/trunk/test/CodeGenCXX/PR5834-constructor-conversion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/PR5834-constructor-conversion.cpp?rev=91861&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenCXX/PR5834-constructor-conversion.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/PR5834-constructor-conversion.cpp Mon Dec 21 18:21:20 2009
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s
+
+// PR5834
+struct ASTMultiMover {};
+struct ASTMultiPtr {
+  ASTMultiPtr();
+  ASTMultiPtr(ASTMultiPtr&);
+  ASTMultiPtr(ASTMultiMover mover);
+  operator ASTMultiMover();
+};
+void f1() {
+  extern void f0(ASTMultiPtr);
+  f0(ASTMultiPtr());
+}





More information about the cfe-commits mailing list