[cfe-commits] r84525 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/CodeGenCXX/derived-to-base-conv.cpp
Fariborz Jahanian
fjahanian at apple.com
Mon Oct 19 12:18:20 PDT 2009
Author: fjahanian
Date: Mon Oct 19 14:18:20 2009
New Revision: 84525
URL: http://llvm.org/viewvc/llvm-project?rev=84525&view=rev
Log:
Copy conversion of an expression to its base class
is a standard convesion and not a user-defined
conversion.
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CodeGenCXX/derived-to-base-conv.cpp
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=84525&r1=84524&r2=84525&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Mon Oct 19 14:18:20 2009
@@ -2539,6 +2539,18 @@
Candidate.Viable = false;
return;
}
+
+ // We won't go through a user-define type conversion function to convert a
+ // derived to base as such conversions are given Conversion Rank. They only
+ // go through a copy constructor. 13.3.3.1.2-p4 [over.ics.user]
+ QualType FromCanon
+ = Context.getCanonicalType(From->getType().getUnqualifiedType());
+ QualType ToCanon = Context.getCanonicalType(ToType).getUnqualifiedType();
+ if (FromCanon == ToCanon || IsDerivedFrom(FromCanon, ToCanon)) {
+ Candidate.Viable = false;
+ return;
+ }
+
// To determine what the conversion from the result of calling the
// conversion function to the type we're eventually trying to
Modified: cfe/trunk/test/CodeGenCXX/derived-to-base-conv.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/derived-to-base-conv.cpp?rev=84525&r1=84524&r2=84525&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/derived-to-base-conv.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/derived-to-base-conv.cpp Mon Oct 19 14:18:20 2009
@@ -5,6 +5,7 @@
// RUN: true
extern "C" int printf(...);
+extern "C" void exit(int);
struct A {
A (const A&) { printf("A::A(const A&)\n"); }
@@ -44,8 +45,35 @@
func(x);
}
+struct Base;
+
+struct Root {
+ operator Base&() { exit(1); }
+};
+
+struct Derived;
+
+struct Base : Root {
+ Base(const Base&) { printf("Base::(const Base&)\n"); }
+ Base() { printf("Base::Base()\n"); }
+ operator Derived&() { exit(1); }
+};
+
+struct Derived : Base {
+};
+
+void foo(Base) {}
+
+void test(Derived bb)
+{
+ // CHECK-LP64-NOT: call __ZN4BasecvR7DerivedEv
+ // CHECK-LP32-NOT: call L__ZN4BasecvR7DerivedEv
+ foo(bb);
+}
// CHECK-LP64: call __ZN1XcvR1BEv
// CHECK-LP64: call __ZN1AC1ERKS_
// CHECK-LP32: call L__ZN1XcvR1BEv
// CHECK-LP32: call L__ZN1AC1ERKS_
+
+
More information about the cfe-commits
mailing list