summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2013-01-13 20:01:12 (EST)
committerSergey Prigogin2013-01-29 20:05:14 (EST)
commitca27491cc2d4b30cbce181b31c68fa611b35ab6e (patch)
tree4d9884b32867fd7cf8fd2f8b386c6a6d032b18b0
parentad05d7423a6e82b702a2160ce227a7e0b958285b (diff)
downloadorg.eclipse.cdt-ca27491cc2d4b30cbce181b31c68fa611b35ab6e.zip
org.eclipse.cdt-ca27491cc2d4b30cbce181b31c68fa611b35ab6e.tar.gz
org.eclipse.cdt-ca27491cc2d4b30cbce181b31c68fa611b35ab6e.tar.bz2
Bug 388805 - False ambiguity in overload resolution with variadic
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java26
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java5
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 d192be3..2d6866f 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;
@@ -1956,13 +1957,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) {