]> granicus.if.org Git - clang/commitdiff
When converting from a type to itself or one of its base classes via a
authorDouglas Gregor <dgregor@apple.com>
Tue, 22 Dec 2009 00:21:20 +0000 (00:21 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 22 Dec 2009 00:21:20 +0000 (00:21 +0000)
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.

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

lib/Sema/SemaOverload.cpp
test/CodeGenCXX/PR5834-constructor-conversion.cpp [new file with mode: 0644]

index fbcb8074289d823671a6c15a2f1d64694f4c9ff7..66aa4845b125b32dd31bded959cc6b4e7d89bf94 100644 (file)
@@ -451,7 +451,8 @@ Sema::TryImplicitConversion(Expr* From, QualType ToType,
       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;
diff --git a/test/CodeGenCXX/PR5834-constructor-conversion.cpp b/test/CodeGenCXX/PR5834-constructor-conversion.cpp
new file mode 100644 (file)
index 0000000..044d8e5
--- /dev/null
@@ -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());
+}