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

Bug 388805 - False ambiguity in overload resolution with variadic

templates

Change-Id: I4d8b73ab5238f98de7b53849b265ebbc6158d62e
Reviewed-on: https://git.eclipse.org/r/9643
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Nathan Ridge 2013-01-13 20:01:12 -05:00 committed by Sergey Prigogin
parent 0ef8976a2a
commit 69c73ec432
3 changed files with 38 additions and 4 deletions

View file

@ -4405,6 +4405,17 @@ public class AST2TemplateTests extends AST2TestBase {
parseAndCheckBindings();
}
// template <typename A>
// void foo(A);
// template <typename A, typename... B>
// void foo(A, B...);
// int main() {
// foo(0);
// }
public void testFunctionTemplatePartialOrdering_388805() throws Exception {
parseAndCheckBindings();
}
// template<typename T> class CT {};
// template<int I> class CTI {};
//

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2012 IBM Corporation and others.
* Copyright (c) 2005, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -81,6 +81,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
@ -1958,13 +1959,34 @@ public class CPPTemplates {
return arg;
}
private static ICPPFunctionType getFunctionTypeIgnoringParametersWithDefaults(ICPPFunction function) {
ICPPParameter[] parameters = function.getParameters();
IType[] parameterTypes = new IType[parameters.length];
int i;
for (i = 0; i < parameters.length; ++i) {
ICPPParameter parameter = parameters[i];
if (!parameter.hasDefaultValue()) {
parameterTypes[i] = parameter.getType();
} else {
break;
}
}
ICPPFunctionType originalType = function.getType();
if (i == parameters.length) // no parameters with default arguments
return originalType;
return new CPPFunctionType(originalType.getReturnType(), ArrayUtil.trim(parameterTypes),
originalType.isConst(), originalType.isVolatile(), originalType.takesVarArgs());
}
private static int compareSpecialization(ICPPFunctionTemplate f1, ICPPFunctionTemplate f2, TypeSelection mode, IASTNode point) throws DOMException {
ICPPFunction transF1 = transferFunctionTemplate(f1, point);
if (transF1 == null)
return -1;
final ICPPFunctionType ft2 = f2.getType();
final ICPPFunctionType transFt1 = transF1.getType();
// Ignore parameters with default arguments in the transformed function template
// as per [temp.func.order] p5.
final ICPPFunctionType transFt1 = getFunctionTypeIgnoringParametersWithDefaults(transF1);
IType[] pars;
IType[] args;
switch(mode) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2012 Wind River Systems, Inc. and others.
* Copyright (c) 2009, 2013 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors:
* Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
* Nathan Ridge
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
@ -431,7 +432,7 @@ public class TemplateArgumentDeduction {
deduct.incPackOffset();
} else {
if (j >= fnParCount)
return result;
return -1;
par= fnPars[j];
if (par instanceof ICPPParameterPackType) {