1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-19 15:05:36 +02:00

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>
This commit is contained in:
Nathan Ridge 2013-01-29 15:59:34 -08:00 committed by Sergey Prigogin
parent 524777cfa8
commit d4cf62a785
4 changed files with 40 additions and 56 deletions

View file

@ -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();
}
}

View file

@ -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;
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) {

View file

@ -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();
}

View file

@ -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;