[cfe-commits] r97161 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/SemaCXX/overload-call.cpp
Douglas Gregor
dgregor at apple.com
Thu Feb 25 11:01:05 PST 2010
Author: dgregor
Date: Thu Feb 25 13:01:05 2010
New Revision: 97161
URL: http://llvm.org/viewvc/llvm-project?rev=97161&view=rev
Log:
Allow us to compare derived-to-base conversions between a reference
binding and a copy-construction. Fixes an overloading problem in the
Clang-on-Clang build.
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/SemaCXX/overload-call.cpp
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=97161&r1=97160&r2=97161&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Feb 25 13:01:05 2010
@@ -2094,32 +2094,6 @@
}
}
- // Compare based on reference bindings.
- if (SCS1.ReferenceBinding && SCS2.ReferenceBinding &&
- SCS1.Second == ICK_Derived_To_Base) {
- // -- binding of an expression of type C to a reference of type
- // B& is better than binding an expression of type C to a
- // reference of type A&,
- if (Context.hasSameUnqualifiedType(FromType1, FromType2) &&
- !Context.hasSameUnqualifiedType(ToType1, ToType2)) {
- if (IsDerivedFrom(ToType1, ToType2))
- return ImplicitConversionSequence::Better;
- else if (IsDerivedFrom(ToType2, ToType1))
- return ImplicitConversionSequence::Worse;
- }
-
- // -- binding of an expression of type B to a reference of type
- // A& is better than binding an expression of type C to a
- // reference of type A&,
- if (!Context.hasSameUnqualifiedType(FromType1, FromType2) &&
- Context.hasSameUnqualifiedType(ToType1, ToType2)) {
- if (IsDerivedFrom(FromType2, FromType1))
- return ImplicitConversionSequence::Better;
- else if (IsDerivedFrom(FromType1, FromType2))
- return ImplicitConversionSequence::Worse;
- }
- }
-
// Ranking of member-pointer types.
if (SCS1.Second == ICK_Pointer_Member && SCS2.Second == ICK_Pointer_Member &&
FromType1->isMemberPointerType() && FromType2->isMemberPointerType() &&
@@ -2156,9 +2130,13 @@
}
}
- if (SCS1.CopyConstructor && SCS2.CopyConstructor &&
+ if ((SCS1.ReferenceBinding || SCS1.CopyConstructor) &&
+ (SCS2.ReferenceBinding || SCS2.CopyConstructor) &&
SCS1.Second == ICK_Derived_To_Base) {
// -- conversion of C to B is better than conversion of C to A,
+ // -- binding of an expression of type C to a reference of type
+ // B& is better than binding an expression of type C to a
+ // reference of type A&,
if (Context.hasSameUnqualifiedType(FromType1, FromType2) &&
!Context.hasSameUnqualifiedType(ToType1, ToType2)) {
if (IsDerivedFrom(ToType1, ToType2))
@@ -2168,6 +2146,9 @@
}
// -- conversion of B to A is better than conversion of C to A.
+ // -- binding of an expression of type B to a reference of type
+ // A& is better than binding an expression of type C to a
+ // reference of type A&,
if (!Context.hasSameUnqualifiedType(FromType1, FromType2) &&
Context.hasSameUnqualifiedType(ToType1, ToType2)) {
if (IsDerivedFrom(FromType2, FromType1))
Modified: cfe/trunk/test/SemaCXX/overload-call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overload-call.cpp?rev=97161&r1=97160&r2=97161&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/overload-call.cpp (original)
+++ cfe/trunk/test/SemaCXX/overload-call.cpp Thu Feb 25 13:01:05 2010
@@ -373,3 +373,16 @@
}
};
}
+
+namespace DerivedToBase {
+ struct A { };
+ struct B : A { };
+ struct C : B { };
+
+ int &f0(const A&);
+ float &f0(B);
+
+ void g() {
+ float &fr = f0(C());
+ }
+}
More information about the cfe-commits
mailing list