diff options
3 files changed, 38 insertions, 4 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index da6898aa9ba..fb687f073fc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -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 {}; // diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index 9a3a3244d2b..73dcc32b4b2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -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) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java index 6319e0c3516..8f8328cffa2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java @@ -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) { |