1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-09 19:43:27 +02:00

Bugs 250582, 250583.

This commit is contained in:
Sergey Prigogin 2008-10-12 20:47:54 +00:00
parent b8c624e10f
commit d2c1866cb7
2 changed files with 50 additions and 43 deletions

View file

@ -6119,12 +6119,22 @@ public class AST2CPPTests extends AST2BaseTest {
assertSame(ors[0], m1);
}
// void f();
//
// void test(int p) {
// f(p);
// }
public void testFunctionExtraArgument() throws Exception {
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
ba.assertProblem("f(p)", 1);
}
// void f(...);
//
// void test(int* p) {
// f(p);
// }
public void _testVariadicFunction_2500582() throws Exception {
public void testVariadicFunction_2500582() throws Exception {
final String comment= getAboveComment();
final boolean[] isCpps= {false, true};
for (boolean isCpp : isCpps) {
@ -6142,7 +6152,7 @@ public class AST2CPPTests extends AST2BaseTest {
// // Should resolve to f(Incomplete*) since 0 can be converted to Incomplete*
// f(0);
// }
public void _testVariadicFunction_2500583() throws Exception {
public void testVariadicFunction_2500583() throws Exception {
final String comment= getAboveComment();
final boolean[] isCpps= {false, true};
for (boolean isCpp : isCpps) {

View file

@ -1991,11 +1991,11 @@ public class CPPSemantics {
return new CPPUsingDeclaration(data.astName, fns);
}
//we don't have any arguments with which to resolve the function
// We don't have any arguments with which to resolve the function
if (data.functionParameters == null) {
return resolveTargetedFunction(data, fns);
}
//reduce our set of candidate functions to only those who have the right number of parameters
// Reduce our set of candidate functions to only those who have the right number of parameters
reduceToViable(data, fns);
if (data.forDefinition() || data.forExplicitInstantiation()) {
@ -2029,7 +2029,7 @@ public class CPPSemantics {
final boolean sourceVoid = (data.functionParameters == null || data.functionParameters.length == 0);
final IType impliedObjectType = data.getImpliedObjectArgument();
// loop over all functions
// Loop over all functions
function_loop: for (int fnIdx = 0; fnIdx < fns.length; fnIdx++) {
currFn= fns[fnIdx];
if (currFn == null || bestFn == currFn) {
@ -2039,7 +2039,6 @@ public class CPPSemantics {
final IType[] targetParameters = getTargetParameterTypes(currFn);
final int useImplicitObj = (currFn instanceof ICPPMethod && !(currFn instanceof ICPPConstructor)) ? 1 : 0;
final int sourceLen= Math.max(sourceParameters.length + useImplicitObj, 1);
final int numTargetParams= Math.max(targetParameters.length, 1 + useImplicitObj);
if (currFnCost == null || currFnCost.length != sourceLen) {
currFnCost= new Cost[sourceLen];
@ -2060,14 +2059,12 @@ public class CPPSemantics {
sourceExp= se instanceof IASTExpression ? (IASTExpression) se : null;
}
if (j < numTargetParams) {
if (j == targetParameters.length) {
target = VOID_TYPE;
} else {
if (j < targetParameters.length) {
target = targetParameters[j];
}
} else {
} else if (currFn.takesVarArgs()) {
varArgs = true;
} else {
target = VOID_TYPE;
}
if (isImpliedObject && ASTInternal.isStatic(currFn, false)) {
@ -2104,7 +2101,7 @@ public class CPPSemantics {
break;
}
//an ambiguity in the user defined conversion sequence is only a problem
// An ambiguity in the user defined conversion sequence is only a problem
// if this function turns out to be the best.
currHasAmbiguousParam = (currCost.userDefined == 1);
if (bestFnCost != null) {
@ -2117,12 +2114,12 @@ public class CPPSemantics {
}
// If function has a parameter match that is better than the current best,
//and another that is worse (or everything was just as good, neither better nor worse).
//then this is an ambiguity (unless we find something better than both later)
// and another that is worse (or everything was just as good, neither better nor worse),
// then this is an ambiguity (unless we find something better than both later).
ambiguous |= (hasWorse && hasBetter) || (!hasWorse && !hasBetter);
if (!hasWorse) {
// if they are both template functions, we can order them that way
// If they are both template functions, we can order them that way
ICPPFunctionTemplate bestAsTemplate= asTemplate(bestFn);
ICPPFunctionTemplate currAsTemplate= asTemplate(currFn);
if (bestAsTemplate != null && currAsTemplate != null) {
@ -2133,7 +2130,7 @@ public class CPPSemantics {
ambiguous = false;
}
} else if (bestAsTemplate != null) {
// we prefer normal functions over template functions, unless we specified template arguments
// We prefer normal functions over template functions, unless we specified template arguments
if (data.preferTemplateFunctions())
ambiguous = false;
else
@ -2145,7 +2142,7 @@ public class CPPSemantics {
ambiguous = false;
}
if (hasBetter) {
//the new best function.
// The new best function.
ambiguous = false;
bestFnCost = currFnCost;
bestHasAmbiguousParam = currHasAmbiguousParam;