1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-05 07:15:39 +02:00

Bug 324096: Follow up on update to overload resolution.

This commit is contained in:
Markus Schorn 2010-09-08 15:17:24 +00:00
parent 14e55ae664
commit 7c42d26023
3 changed files with 104 additions and 76 deletions

View file

@ -8937,4 +8937,23 @@ public class AST2CPPTests extends AST2BaseTest {
assertEquals(1, names.length); assertEquals(1, names.length);
assertTrue(names[0].resolveBinding() instanceof ICPPConstructor); assertTrue(names[0].resolveBinding() instanceof ICPPConstructor);
} }
// void g(char *);
// void f(char *);
// void f(const char *);
// void testa() {
// f("abc");
// g("abc");
// }
public void testRankingOfDeprecatedConversionOnStringLiteral() throws Exception {
String code= getAboveComment();
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
IFunction g= bh.assertNonProblem("g(char *)", 1);
IFunction fconst= bh.assertNonProblem("f(const char *)", 1);
IBinding ref= bh.assertNonProblem("f(\"abc\")", 1);
assertSame(fconst, ref);
ref= bh.assertNonProblem("g(\"abc\")", 1);
assertSame(g, ref);
}
} }

View file

@ -480,8 +480,8 @@ public class Conversions {
final IValue av= at.getSize(); final IValue av= at.getSize();
final IValue sv= st.getSize(); final IValue sv= st.getSize();
if (av == sv || (av != null && av.equals(sv))) { if (av == sv || (av != null && av.equals(sv))) {
t= SemanticUtil.getNestedType(at.getType(), TDEF | REF); t= SemanticUtil.getNestedType(at.getType(), TDEF | REF | ALLCVQ);
s= SemanticUtil.getNestedType(st.getType(), TDEF | REF); s= SemanticUtil.getNestedType(st.getType(), TDEF | REF | ALLCVQ);
} else { } else {
return -1; return -1;
} }
@ -797,7 +797,7 @@ public class Conversions {
*/ */
private static final boolean lvalue_to_rvalue(final Cost cost) { private static final boolean lvalue_to_rvalue(final Cost cost) {
IType target = getNestedType(cost.target, REF | TDEF | ALLCVQ); IType target = getNestedType(cost.target, REF | TDEF | ALLCVQ);
IType source= getNestedType(cost.source, REF | TDEF | ALLCVQ); IType source= getNestedType(cost.source, REF | TDEF);
// 4.2 array to pointer conversion // 4.2 array to pointer conversion
if (source instanceof IArrayType) { if (source instanceof IArrayType) {
@ -826,15 +826,14 @@ public class Conversions {
} }
} }
} }
if (!isConverted && (target instanceof IPointerType || target instanceof IBasicType)) { if (!isConverted) {
source = new CPPPointerType(getNestedType(arrayType.getType(), TDEF)); source = new CPPPointerType(getNestedType(arrayType.getType(), TDEF));
} }
} else if (target instanceof IPointerType) { } else if (source instanceof IFunctionType) {
// 4.3 function to pointer conversion // 4.3 function to pointer conversion
final IType targetPtrTgt= getNestedType(((IPointerType) target).getType(), TDEF);
if (targetPtrTgt instanceof IFunctionType && source instanceof IFunctionType) {
source = new CPPPointerType(source); source = new CPPPointerType(source);
} } else {
source = getNestedType(source, TDEF | REF | ALLCVQ);
} }
if (source == null || target == null) { if (source == null || target == null) {

View file

@ -188,7 +188,6 @@ public class TemplateArgumentDeduction {
boolean isDependentPar= CPPTemplates.isDependentType(par); boolean isDependentPar= CPPTemplates.isDependentType(par);
if (checkExactMatch || isDependentPar) { if (checkExactMatch || isDependentPar) {
boolean isReferenceTypeParameter= false;
IType arg = fnArgs[j]; IType arg = fnArgs[j];
par= SemanticUtil.getNestedType(par, SemanticUtil.TDEF); // adjustParameterType preserves typedefs par= SemanticUtil.getNestedType(par, SemanticUtil.TDEF); // adjustParameterType preserves typedefs
@ -200,9 +199,11 @@ public class TemplateArgumentDeduction {
// Check if this is a deduced context // Check if this is a deduced context
IType inner= Conversions.getInitListType(par); IType inner= Conversions.getInitListType(par);
if (inner != null) { if (inner != null) {
IType[] types = ((InitializerListType) arg).getExpressionTypes(); final InitializerListType initListType = (InitializerListType) arg;
for (IType iType : types) { IType[] types = initListType.getExpressionTypes();
if (!deduct.fromType(inner, iType, false)) ValueCategory[] valueCats = initListType.getValueCategories();
for (int i = 0; i < types.length; i++) {
if (!deduceFromFunctionArg(inner, types[i], valueCats[i], checkExactMatch, isDependentPar, deduct))
return false; return false;
} }
} }
@ -210,18 +211,39 @@ public class TemplateArgumentDeduction {
} }
// 14.8.2.1-2 // 14.8.2.1-2
ValueCategory cat= argIsLValue != null ? argIsLValue[j] : LVALUE;
if (!deduceFromFunctionArg(par, arg, cat, checkExactMatch, isDependentPar, deduct)) {
return false;
}
}
}
// Bug 309564: For partial ordering not all arguments need to be deduced
if (checkExactMatch)
return true;
if (!deduct.fExplicitArgs.mergeToExplicit(deduct.fDeducedArgs))
return false;
return verifyDeduction(tmplPars, map, true);
} catch (DOMException e) {
}
return false;
}
private static boolean deduceFromFunctionArg(IType par, IType arg, ValueCategory valueCat, boolean checkExactMatch, boolean isDependentPar, TemplateArgumentDeduction deduct) throws DOMException {
boolean isReferenceTypeParameter= false;
if (par instanceof ICPPReferenceType) { if (par instanceof ICPPReferenceType) {
// If P is an rvalue reference to a cv-unqualified template parameter and the argument is an // If P is an rvalue reference to a cv-unqualified template parameter and the argument is an
// lvalue, the type "lvalue reference to A" is used in place of A for type deduction. // lvalue, the type "lvalue reference to A" is used in place of A for type deduction.
isReferenceTypeParameter= true; isReferenceTypeParameter= true;
final ICPPReferenceType refPar = (ICPPReferenceType) par; final ICPPReferenceType refPar = (ICPPReferenceType) par;
if (refPar.isRValueReference() && refPar.getType() instanceof ICPPTemplateParameter && if (refPar.isRValueReference() && refPar.getType() instanceof ICPPTemplateParameter &&
argIsLValue != null && argIsLValue[j] == LVALUE) { valueCat == LVALUE) {
arg= new CPPReferenceType(getSimplifiedType(arg), false); arg= new CPPReferenceType(getSimplifiedType(arg), false);
} else { } else {
arg= getArgumentTypeForDeduction(arg, true); arg= getArgumentTypeForDeduction(arg, true);
} }
par= SemanticUtil.getNestedType(par, SemanticUtil.REF | SemanticUtil.TDEF); par= SemanticUtil.getNestedType(par, REF | TDEF);
} else { } else {
arg= getArgumentTypeForDeduction(arg, false); arg= getArgumentTypeForDeduction(arg, false);
} }
@ -275,19 +297,7 @@ public class TemplateArgumentDeduction {
if (!instantiated.isSameType(arg)) if (!instantiated.isSameType(arg))
return false; return false;
} }
}
}
// Bug 309564: For partial ordering not all arguments need to be deduced
if (checkExactMatch)
return true; return true;
if (!deduct.fExplicitArgs.mergeToExplicit(deduct.fDeducedArgs))
return false;
return verifyDeduction(tmplPars, map, true);
} catch (DOMException e) {
}
return false;
} }
/** /**