| author | Nathan Ridge | 2013-01-13 20:01:12 (EST) |
|---|---|---|
| committer | Sergey Prigogin | 2013-01-29 18:41:31 (EST) |
| commit | 69c73ec432fde23f438e83fa93a4940fb30034bf (patch) (side-by-side diff) | |
| tree | 909c792ec11a4ec281095c4ccb482b35bedc9ac4 | |
| parent | 0ef8976a2a4ae73d7f2009cf4fcaec6d8891c8be (diff) | |
| download | org.eclipse.cdt-69c73ec432fde23f438e83fa93a4940fb30034bf.zip org.eclipse.cdt-69c73ec432fde23f438e83fa93a4940fb30034bf.tar.gz org.eclipse.cdt-69c73ec432fde23f438e83fa93a4940fb30034bf.tar.bz2 | |
Bug 388805 - False ambiguity in overload resolution with variadicrefs/changes/43/9643/3
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>
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 da6898a..fb687f0 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 9a3a324..73dcc32 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 6319e0c..8f8328c 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) { |

