Type conversion and function call overload resolution bug fixes.

This commit is contained in:
Matt Pharr
2011-07-04 15:11:28 +01:00
parent 3b3015162f
commit c6bc8fd64f

View File

@@ -164,15 +164,20 @@ Expr::TypeConv(const Type *toType, const char *errorMsgBase, bool failureOk) {
if (Type::Equal(toType->GetReferenceTarget(), if (Type::Equal(toType->GetReferenceTarget(),
fromType->GetReferenceTarget()->GetAsConstType())) fromType->GetReferenceTarget()->GetAsConstType()))
return new TypeCastExpr(toType, this, pos); return new TypeCastExpr(toType, this, pos);
#if 0
// FIXME: why is this commented out?? const ArrayType *atFrom = dynamic_cast<const ArrayType *>(fromType->GetReferenceTarget());
const ArrayType *atTo = dynamic_cast<const ArrayType *>(toType->GetReferenceTarget());
if (atFrom != NULL && atTo != NULL &&
Type::Equal(atFrom->GetElementType(), atTo->GetElementType()))
return new TypeCastExpr(toType, this, pos);
else { else {
Error(pos, "Can't convert between incompatible reference types \"%s\" " if (!failureOk)
"and \"%s\".", fromType->GetString().c_str(), Error(pos, "Can't convert between incompatible reference types \"%s\" "
toType->GetString().c_str()); "and \"%s\" for %s.", fromType->GetString().c_str(),
toType->GetString().c_str(), errorMsgBase);
return NULL; return NULL;
} }
#endif
} }
else { else {
// convert from a reference T -> T // convert from a reference T -> T
@@ -1897,8 +1902,12 @@ lPrintFunctionOverloads(const std::vector<Symbol *> &matches) {
static bool static bool
lExactMatch(Expr *callArg, const Type *funcArgType) { lExactMatch(Expr *callArg, const Type *funcArgType) {
const Type *callType = callArg->GetType(); const Type *callType = callArg->GetType();
// FIXME MOVE THESE TWO TO ALWAYS DO IT...
if (dynamic_cast<const ReferenceType *>(callType) == NULL) if (dynamic_cast<const ReferenceType *>(callType) == NULL)
callType = callType->GetAsNonConstType(); callType = callType->GetAsNonConstType();
if (dynamic_cast<const ReferenceType *>(funcArgType) != NULL &&
dynamic_cast<const ReferenceType *>(callType) == NULL)
callType = new ReferenceType(callType, funcArgType->IsConstType());
return Type::Equal(callType, funcArgType); return Type::Equal(callType, funcArgType);
} }
@@ -1952,7 +1961,7 @@ lMatchWithTypeConvSameVariability(Expr *callArg, const Type *funcArgType) {
/** Helper function used for function overload resolution: returns true if /** Helper function used for function overload resolution: returns true if
there is any type conversino that gets us from the caller argument type there is any type conversion that gets us from the caller argument type
to the function argument type. to the function argument type.
*/ */
static bool static bool
@@ -2072,7 +2081,7 @@ FunctionCallExpr::resolveFunctionOverloads() {
// Try to find the best overload for the function... // Try to find the best overload for the function...
// Is there an exact match that doesn't require any argument type // Is there an exact match that doesn't require any argument type
// conversion at all? // conversion (other than converting type -> reference type)?
if (tryResolve(lExactMatch)) if (tryResolve(lExactMatch))
return; return;
@@ -2099,10 +2108,11 @@ FunctionCallExpr::resolveFunctionOverloads() {
// failure :-( // failure :-(
const char *funName = fse->candidateFunctions->front()->name.c_str(); const char *funName = fse->candidateFunctions->front()->name.c_str();
Error(pos, "Unable to find matching overload for call to function \"%s\". " Error(pos, "Unable to find matching overload for call to function \"%s\".",
"Candidates are:", funName); funName);
fprintf(stderr, "Candidates are:\n");
lPrintFunctionOverloads(*fse->candidateFunctions); lPrintFunctionOverloads(*fse->candidateFunctions);
fprintf(stderr, "Passed types: %s(", funName); fprintf(stderr, "Passed types:\n\t%s(", funName);
for (unsigned int i = 0; i < args->exprs.size(); ++i) { for (unsigned int i = 0; i < args->exprs.size(); ++i) {
const Type *t = args->exprs[i]->GetType(); const Type *t = args->exprs[i]->GetType();
if (t) if (t)