mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 23:05:47 +02:00
Bug 324096: Follow up on update to overload resolution.
This commit is contained in:
parent
14e55ae664
commit
7c42d26023
3 changed files with 104 additions and 76 deletions
|
@ -8937,4 +8937,23 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertEquals(1, names.length);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -480,8 +480,8 @@ public class Conversions {
|
|||
final IValue av= at.getSize();
|
||||
final IValue sv= st.getSize();
|
||||
if (av == sv || (av != null && av.equals(sv))) {
|
||||
t= SemanticUtil.getNestedType(at.getType(), TDEF | REF);
|
||||
s= SemanticUtil.getNestedType(st.getType(), TDEF | REF);
|
||||
t= SemanticUtil.getNestedType(at.getType(), TDEF | REF | ALLCVQ);
|
||||
s= SemanticUtil.getNestedType(st.getType(), TDEF | REF | ALLCVQ);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
@ -797,7 +797,7 @@ public class Conversions {
|
|||
*/
|
||||
private static final boolean lvalue_to_rvalue(final Cost cost) {
|
||||
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
|
||||
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));
|
||||
}
|
||||
} else if (target instanceof IPointerType) {
|
||||
} else if (source instanceof IFunctionType) {
|
||||
// 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);
|
||||
}
|
||||
} else {
|
||||
source = getNestedType(source, TDEF | REF | ALLCVQ);
|
||||
}
|
||||
|
||||
if (source == null || target == null) {
|
||||
|
|
|
@ -188,7 +188,6 @@ public class TemplateArgumentDeduction {
|
|||
|
||||
boolean isDependentPar= CPPTemplates.isDependentType(par);
|
||||
if (checkExactMatch || isDependentPar) {
|
||||
boolean isReferenceTypeParameter= false;
|
||||
IType arg = fnArgs[j];
|
||||
par= SemanticUtil.getNestedType(par, SemanticUtil.TDEF); // adjustParameterType preserves typedefs
|
||||
|
||||
|
@ -200,9 +199,11 @@ public class TemplateArgumentDeduction {
|
|||
// Check if this is a deduced context
|
||||
IType inner= Conversions.getInitListType(par);
|
||||
if (inner != null) {
|
||||
IType[] types = ((InitializerListType) arg).getExpressionTypes();
|
||||
for (IType iType : types) {
|
||||
if (!deduct.fromType(inner, iType, false))
|
||||
final InitializerListType initListType = (InitializerListType) arg;
|
||||
IType[] types = initListType.getExpressionTypes();
|
||||
ValueCategory[] valueCats = initListType.getValueCategories();
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
if (!deduceFromFunctionArg(inner, types[i], valueCats[i], checkExactMatch, isDependentPar, deduct))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -210,18 +211,39 @@ public class TemplateArgumentDeduction {
|
|||
}
|
||||
|
||||
// 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 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.
|
||||
isReferenceTypeParameter= true;
|
||||
final ICPPReferenceType refPar = (ICPPReferenceType) par;
|
||||
if (refPar.isRValueReference() && refPar.getType() instanceof ICPPTemplateParameter &&
|
||||
argIsLValue != null && argIsLValue[j] == LVALUE) {
|
||||
valueCat == LVALUE) {
|
||||
arg= new CPPReferenceType(getSimplifiedType(arg), false);
|
||||
} else {
|
||||
arg= getArgumentTypeForDeduction(arg, true);
|
||||
}
|
||||
par= SemanticUtil.getNestedType(par, SemanticUtil.REF | SemanticUtil.TDEF);
|
||||
par= SemanticUtil.getNestedType(par, REF | TDEF);
|
||||
} else {
|
||||
arg= getArgumentTypeForDeduction(arg, false);
|
||||
}
|
||||
|
@ -275,19 +297,7 @@ public class TemplateArgumentDeduction {
|
|||
if (!instantiated.isSameType(arg))
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue