1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 367560: Pack expansions as function args.

This commit is contained in:
Markus Schorn 2012-01-02 15:06:17 +01:00
parent 282daa7a8e
commit ae559e16d8
3 changed files with 26 additions and 4 deletions

View file

@ -5668,4 +5668,13 @@ public class AST2TemplateTests extends AST2BaseTest {
public void testResolvingAutoTypeWithDependentExpression_367472() throws Exception {
parseAndCheckBindings();
}
// void foo(int, int);
// template <typename... Args> void bar(Args... args) {
// foo(1,2,args...);
// foo(args...);
// }
public void testPackExpansionsAsArguments_367560() throws Exception {
parseAndCheckBindings();
}
}

View file

@ -2276,7 +2276,8 @@ public class CPPSemantics {
private static ICPPFunction[] selectByArgumentCount(LookupData data, ICPPFunction[] functions) throws DOMException {
assert data.forDeclaration() == null;
int argumentCount = data.getFunctionArgumentCount();
final int argumentCount = data.getFunctionArgumentCount();
final int packExpansionCount= data.getFunctionArgumentPackExpansionCount();
// Trim the list down to the set of viable functions
ICPPFunction[] result= new ICPPFunction[functions.length];
@ -2300,11 +2301,11 @@ public class CPPSemantics {
numArgs--;
boolean ok;
if (numArgs > numPars) {
// more arguments than parameters --> need ellipsis or parameter pack
if (numArgs-packExpansionCount > numPars) {
// More arguments than parameters --> need ellipsis or parameter pack
ok= fn.takesVarArgs() || fn.hasParameterPack();
} else {
ok = numArgs >= fn.getRequiredArgumentCount();
ok = numArgs >= fn.getRequiredArgumentCount() || packExpansionCount > 0;
}
if (ok) {
if (fn instanceof IIndexBinding) {

View file

@ -52,6 +52,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpansionExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
@ -533,6 +534,17 @@ public class LookupData {
return 0;
}
public int getFunctionArgumentPackExpansionCount() {
int count= 0;
if (functionArgs != null) {
for (IASTInitializerClause arg : functionArgs) {
if (arg instanceof ICPPASTPackExpansionExpression)
count++;
}
}
return count;
}
public boolean hasFunctionArguments() {
return functionArgs != null;
}