Reapply the reference-binding patch applied below, along with a fix to

ensure that we complete the type when we need to look at constructors
during reference binding.

When determining whether the two types involved in reference binding
are reference-compatible, reference-related, etc., do not complete the
type of the reference itself because it is not necessary to determine
well-formedness of the program. Complete the type that we are binding
to, since that can affect whether we know about a derived-to-base
conversion. 

Re-fixes PR7080.

llvm-svn: 103283
This commit is contained in:
Douglas Gregor 2010-05-07 19:42:26 +00:00
parent 7828ab1ed9
commit 496e8b345c
3 changed files with 26 additions and 5 deletions

View File

@ -2245,11 +2245,11 @@ static OverloadingResult TryRefInitWithConversionFunction(Sema &S,
bool AllowExplicit = Kind.getKind() == InitializationKind::IK_Direct; bool AllowExplicit = Kind.getKind() == InitializationKind::IK_Direct;
const RecordType *T1RecordType = 0; const RecordType *T1RecordType = 0;
if (AllowRValues && (T1RecordType = T1->getAs<RecordType>())) { if (AllowRValues && (T1RecordType = T1->getAs<RecordType>()) &&
!S.RequireCompleteType(Kind.getLocation(), T1, 0)) {
// The type we're converting to is a class type. Enumerate its constructors // The type we're converting to is a class type. Enumerate its constructors
// to see if there is a suitable conversion. // to see if there is a suitable conversion.
CXXRecordDecl *T1RecordDecl = cast<CXXRecordDecl>(T1RecordType->getDecl()); CXXRecordDecl *T1RecordDecl = cast<CXXRecordDecl>(T1RecordType->getDecl());
DeclarationName ConstructorName DeclarationName ConstructorName
= S.Context.DeclarationNames.getCXXConstructorName( = S.Context.DeclarationNames.getCXXConstructorName(
S.Context.getCanonicalType(T1).getUnqualifiedType()); S.Context.getCanonicalType(T1).getUnqualifiedType());
@ -2281,7 +2281,9 @@ static OverloadingResult TryRefInitWithConversionFunction(Sema &S,
} }
} }
if (const RecordType *T2RecordType = T2->getAs<RecordType>()) { const RecordType *T2RecordType = 0;
if ((T2RecordType = T2->getAs<RecordType>()) &&
!S.RequireCompleteType(Kind.getLocation(), T2, 0)) {
// The type we're converting from is a class type, enumerate its conversion // The type we're converting from is a class type, enumerate its conversion
// functions. // functions.
CXXRecordDecl *T2RecordDecl = cast<CXXRecordDecl>(T2RecordType->getDecl()); CXXRecordDecl *T2RecordDecl = cast<CXXRecordDecl>(T2RecordType->getDecl());

View File

@ -2289,8 +2289,7 @@ Sema::CompareReferenceRelationship(SourceLocation Loc,
// T1 is a base class of T2. // T1 is a base class of T2.
if (UnqualT1 == UnqualT2) if (UnqualT1 == UnqualT2)
DerivedToBase = false; DerivedToBase = false;
else if (!RequireCompleteType(Loc, OrigT1, PDiag()) && else if (!RequireCompleteType(Loc, OrigT2, PDiag()) &&
!RequireCompleteType(Loc, OrigT2, PDiag()) &&
IsDerivedFrom(UnqualT2, UnqualT1)) IsDerivedFrom(UnqualT2, UnqualT1))
DerivedToBase = true; DerivedToBase = true;
else else

View File

@ -99,3 +99,23 @@ namespace TemporaryObjectCopy {
template void f(int); template void f(int);
} }
namespace PR7080 {
template <class T, class U>
class X
{
typedef char true_t;
class false_t { char dummy[2]; };
static true_t dispatch(U);
static false_t dispatch(...);
static T trigger();
public:
enum { value = sizeof(dispatch(trigger())) == sizeof(true_t) };
};
template <class T>
class rv : public T
{ };
bool x = X<int, rv<int>&>::value;
}