From: Douglas Gregor Date: Tue, 13 Apr 2010 15:07:45 +0000 (+0000) Subject: During referencing binding, only consider conversion functions for X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d1fed3e8595a15edd7e14cee166ef90634fcf141;p=clang During referencing binding, only consider conversion functions for direct reference binding when the source and target types are not reference-related. Fixes PR6066. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101132 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 46ed857a9e..cc83e65b36 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -4577,14 +4577,16 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, } } - // -- has a class type (i.e., T2 is a class type) and can be - // implicitly converted to an lvalue of type "cv3 T3," - // where "cv1 T1" is reference-compatible with "cv3 T3" - // 92) (this conversion is selected by enumerating the - // applicable conversion functions (13.3.1.6) and choosing - // the best one through overload resolution (13.3)), + // -- has a class type (i.e., T2 is a class type), where T1 is + // not reference-related to T2, and can be implicitly + // converted to an lvalue of type "cv3 T3," where "cv1 T1" + // is reference-compatible with "cv3 T3" 92) (this + // conversion is selected by enumerating the applicable + // conversion functions (13.3.1.6) and choosing the best + // one through overload resolution (13.3)), if (!isRValRef && !SuppressUserConversions && T2->isRecordType() && - !RequireCompleteType(DeclLoc, T2, 0)) { + !RequireCompleteType(DeclLoc, T2, 0) && + RefRelationship == Ref_Incompatible) { CXXRecordDecl *T2RecordDecl = dyn_cast(T2->getAs()->getDecl()); diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5.cpp index 4c7ee942bd..51d61a52a6 100644 --- a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5.cpp +++ b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5.cpp @@ -22,3 +22,19 @@ namespace PR6264 { T bar = S(); } } + +namespace PR6066 { + struct B { }; + struct A : B { + operator B*(); + operator B&(); // expected-warning{{conversion function converting 'PR6066::A' to its base class 'PR6066::B' will never be used}} + }; + + void f(B&); // no rvalues accepted + void f(B*); + + int g() { + f(A()); // calls f(B*) + return 0; + } +}