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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63554 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 1fa703c..7219f19 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -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;
}
}