1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Bug 404245 - Check that a function call has enough arguments after

template argument deduction

Change-Id: I2824e908dc6ea9796c9400e81f3ef34d97406dc6
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
Reviewed-on: https://git.eclipse.org/r/31345
Tested-by: Hudson CI
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Nathan Ridge 2014-08-10 02:48:09 -04:00 committed by Sergey Prigogin
parent 42235704cb
commit 3e540156b6
4 changed files with 28 additions and 5 deletions

View file

@ -8047,6 +8047,17 @@ public class AST2TemplateTests extends AST2TestBase {
parseAndCheckBindings();
}
// template <typename... Args>
// void waldo(Args...);
//
// int main() {
// waldo<int>();
// }
public void testExplicitArgumentsForParameterPack_404245() throws Exception {
BindingAssertionHelper helper = getAssertionHelper();
helper.assertProblem("waldo<int>()", "waldo<int>");
}
// template <typename T>
// struct A {};
//

View file

@ -654,7 +654,10 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
@Override
public boolean hasParameterPack() {
ICPPParameter[] pars= getParameters();
return hasParameterPack(getParameters());
}
public static boolean hasParameterPack(ICPPParameter[] pars) {
return pars.length > 0 && pars[pars.length - 1].isParameterPack();
}

View file

@ -69,12 +69,12 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
@Override
public int getRequiredArgumentCount() {
return ((ICPPFunction) getSpecializedBinding()).getRequiredArgumentCount();
return CPPFunction.getRequiredArgumentCount(getParameters());
}
@Override
public boolean hasParameterPack() {
return ((ICPPFunction) getSpecializedBinding()).hasParameterPack();
return CPPFunction.hasParameterPack(getParameters());
}
@Override

View file

@ -2041,8 +2041,17 @@ public class CPPTemplates {
IBinding instance= instantiateFunctionTemplate(template, args, map, point);
if (instance instanceof ICPPFunction) {
final ICPPFunction f = (ICPPFunction) instance;
if (SemanticUtil.isValidType(f.getType()))
return f;
if (SemanticUtil.isValidType(f.getType())) {
// The number of arguments have been checked against the function
// template's required argument count at an earlier stage. However,
// the process of instantiation can increase the required argument
// count by expanding parameter packs. If arguments are provided
// for a parameter pack explicitly, it's possible for deduction to
// succeed without having enough function arguments to match a
// corresponding function parameter pack - so we check again.
if (fnArgs.size() >= f.getRequiredArgumentCount())
return f;
}
}
}
} catch (DOMException e) {