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:
parent
282daa7a8e
commit
ae559e16d8
3 changed files with 26 additions and 4 deletions
|
@ -5668,4 +5668,13 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
public void testResolvingAutoTypeWithDependentExpression_367472() throws Exception {
|
public void testResolvingAutoTypeWithDependentExpression_367472() throws Exception {
|
||||||
parseAndCheckBindings();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2276,7 +2276,8 @@ public class CPPSemantics {
|
||||||
private static ICPPFunction[] selectByArgumentCount(LookupData data, ICPPFunction[] functions) throws DOMException {
|
private static ICPPFunction[] selectByArgumentCount(LookupData data, ICPPFunction[] functions) throws DOMException {
|
||||||
assert data.forDeclaration() == null;
|
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
|
// Trim the list down to the set of viable functions
|
||||||
ICPPFunction[] result= new ICPPFunction[functions.length];
|
ICPPFunction[] result= new ICPPFunction[functions.length];
|
||||||
|
@ -2300,11 +2301,11 @@ public class CPPSemantics {
|
||||||
numArgs--;
|
numArgs--;
|
||||||
|
|
||||||
boolean ok;
|
boolean ok;
|
||||||
if (numArgs > numPars) {
|
if (numArgs-packExpansionCount > numPars) {
|
||||||
// more arguments than parameters --> need ellipsis or parameter pack
|
// More arguments than parameters --> need ellipsis or parameter pack
|
||||||
ok= fn.takesVarArgs() || fn.hasParameterPack();
|
ok= fn.takesVarArgs() || fn.hasParameterPack();
|
||||||
} else {
|
} else {
|
||||||
ok = numArgs >= fn.getRequiredArgumentCount();
|
ok = numArgs >= fn.getRequiredArgumentCount() || packExpansionCount > 0;
|
||||||
}
|
}
|
||||||
if (ok) {
|
if (ok) {
|
||||||
if (fn instanceof IIndexBinding) {
|
if (fn instanceof IIndexBinding) {
|
||||||
|
|
|
@ -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.ICPPASTFieldReference;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList;
|
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.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.ICPPASTQualifiedName;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||||
|
@ -533,6 +534,17 @@ public class LookupData {
|
||||||
return 0;
|
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() {
|
public boolean hasFunctionArguments() {
|
||||||
return functionArgs != null;
|
return functionArgs != null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue