Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2013-01-29 23:59:34 +0000
committerSergey Prigogin2013-01-30 00:14:37 +0000
commitd4cf62a7853199a723b45d6454586e67ae3332c4 (patch)
tree2b2ff6f8b45bf541e073ca3d6ab24640c14c92a4
parent524777cfa8cc8e0456727b85d0bcfb71e152ba35 (diff)
downloadorg.eclipse.cdt-d4cf62a7853199a723b45d6454586e67ae3332c4.tar.gz
org.eclipse.cdt-d4cf62a7853199a723b45d6454586e67ae3332c4.tar.xz
org.eclipse.cdt-d4cf62a7853199a723b45d6454586e67ae3332c4.zip
Bug 398044 - Error involving partial ordering of class template
specializations Change-Id: Ia4a2d8760c6122e5aeec81524a20a3fa14a5a3ac Reviewed-on: https://git.eclipse.org/r/9645 Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java30
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java19
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java45
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java2
4 files changed, 40 insertions, 56 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 789af2f3408..f1ef857a7a3 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
@@ -7068,4 +7068,34 @@ public class AST2TemplateTests extends AST2TestBase {
public void testVariadicNonTypeTemplateParameter_382074() throws Exception {
parseAndCheckBindings();
}
+
+ // template <typename...>
+ // struct common_type;
+ // template <typename T>
+ // struct common_type<T> {
+ // typedef int type;
+ // };
+ // template <typename T, typename... U>
+ // struct common_type<T, U...> {
+ // typedef int type;
+ // };
+ // typedef common_type<int>::type type;
+ public void testClassTemplateSpecializationPartialOrdering_398044a() throws Exception {
+ parseAndCheckBindings();
+ }
+
+ // template <typename>
+ // class A;
+ // template <typename R, typename... Args>
+ // class A<R(*)(Args...)> {
+ // };
+ // template <typename R>
+ // class A<R*> {
+ // };
+ // int main() {
+ // A<bool(*)()> mf;
+ // }
+ public void testClassTemplateSpecializationPartialOrdering_398044b() throws Exception {
+ parseAndCheckBindings();
+ }
}
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 73dcc32b4b2..8d4f25cf045 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
@@ -2140,8 +2140,6 @@ public class CPPTemplates {
final ICPPTemplateParameter[] tpars2 = f2.getTemplateParameters();
final ICPPTemplateArgument[] targs1 = f1.getTemplateArguments();
final ICPPTemplateArgument[] targs2 = f2.getTemplateArguments();
- if (targs1.length != targs2.length)
- return false;
// Transfer arguments of specialization 1
final int tpars1Len = tpars1.length;
@@ -2151,22 +2149,17 @@ public class CPPTemplates {
final ICPPTemplateParameter param = tpars1[i];
final ICPPTemplateArgument arg = uniqueArg(param);
args[i]= arg;
- transferMap.put(param, arg);
+ if (param.isParameterPack()) {
+ transferMap.put(param, new ICPPTemplateArgument[] { arg });
+ } else {
+ transferMap.put(param, arg);
+ }
}
final ICPPTemplateArgument[] transferredArgs1 = instantiateArguments(targs1, transferMap, -1, null, point, false);
// Deduce arguments for specialization 2
final CPPTemplateParameterMap deductionMap= new CPPTemplateParameterMap(2);
- if (!TemplateArgumentDeduction.fromTemplateArguments(tpars2, targs2, transferredArgs1, deductionMap, point))
- return false;
-
- // Compare
- for (int i = 0; i < targs2.length; i++) {
- ICPPTemplateArgument transferredArg2= instantiateArgument(targs2[i], deductionMap, -1, null, point);
- if (!transferredArg2.isSameValue(transferredArgs1[i]))
- return false;
- }
- return true;
+ return TemplateArgumentDeduction.fromTemplateArguments(tpars2, targs2, transferredArgs1, deductionMap, point);
}
static boolean isValidType(IType t) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java
index 5431c752d7c..5e86257e167 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2012 IBM Corporation and others.
+ * Copyright (c) 2004, 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
@@ -11,6 +11,7 @@
* Bryan Wilkinson (QNX)
* Andrew Ferguson (Symbian)
* Sergey Prigogin (Google)
+ * Nathan Ridge
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
@@ -49,7 +50,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
@@ -663,46 +663,7 @@ public class SemanticUtil {
return -1;
}
- public static boolean containsUniqueTypeForParameterPack(IType type) {
- if (type instanceof ICPPFunctionType) {
- final ICPPFunctionType ft = (ICPPFunctionType) type;
- if (containsUniqueTypeForParameterPack(ft.getReturnType()))
- return true;
-
- for (IType pt : ft.getParameterTypes()) {
- if (containsUniqueTypeForParameterPack(pt))
- return true;
- }
- return false;
- }
-
- if (type instanceof ICPPPointerToMemberType) {
- if (containsUniqueTypeForParameterPack(((ICPPPointerToMemberType) type).getMemberOfClass()))
- return true;
- }
-
- if (type instanceof IBinding) {
- IBinding owner = ((IBinding) type).getOwner();
- if (owner instanceof IType) {
- if (containsUniqueTypeForParameterPack((IType) owner))
- return true;
- }
- }
-
- if (type instanceof ICPPTemplateInstance) {
- ICPPTemplateArgument[] args = ((ICPPTemplateInstance) type).getTemplateArguments();
- for (ICPPTemplateArgument arg : args) {
- if (containsUniqueTypeForParameterPack(arg.getTypeValue()))
- return true;
- }
- }
-
- if (type instanceof ITypeContainer) {
- final ITypeContainer tc = (ITypeContainer) type;
- final IType nestedType= tc.getType();
- return containsUniqueTypeForParameterPack(nestedType);
- }
-
+ public static boolean isUniqueTypeForParameterPack(IType type) {
if (type instanceof UniqueType) {
return ((UniqueType) type).isForParameterPack();
}
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 eeafbef7f77..555f1ec9e77 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
@@ -970,7 +970,7 @@ public class TemplateArgumentDeduction {
return false;
return fDeducedArgs.putPackElement(parID, fPackOffset, arg, fPackSize);
}
- if (SemanticUtil.containsUniqueTypeForParameterPack(arg.getTypeValue()))
+ if (SemanticUtil.isUniqueTypeForParameterPack(arg.getTypeValue()))
return false;
fDeducedArgs.put(parID, arg);
return true;

Back to the top