From a48e822d59413e08421eefcb36af8fcdbe7f71fe Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 12 Nov 2012 11:21:32 -0800 Subject: [PATCH] Bug 394024 - Template resolution problem with unsigned int non type parameter. A better fix. --- .../core/dom/parser/cpp/CPPBasicType.java | 6 +---- .../semantics/TemplateArgumentDeduction.java | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java index baf5e299e3c..bf2677b028a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java @@ -32,7 +32,6 @@ import org.eclipse.core.runtime.CoreException; */ public class CPPBasicType implements ICPPBasicType, ISerializableType { private static final int FROM_STRING_LITERAL = 1 << 31; - public static final int UNSPECIFIED_MODIFIERS = 1 << 30; public static final CPPBasicType BOOLEAN = new CPPBasicType(Kind.eBoolean, 0, null); public static final CPPBasicType NULL_PTR = new CPPBasicType(Kind.eNullPtr, 0, null); @@ -127,9 +126,6 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { int modifiers = getModifiers(); int otherModifiers = other.getModifiers(); - if ((modifiers & UNSPECIFIED_MODIFIERS) != 0 || (otherModifiers & UNSPECIFIED_MODIFIERS) != 0) { - return true; - } if (fKind == Kind.eInt) { // Signed int and int are equivalent. return (modifiers & ~IS_SIGNED) == (otherModifiers & ~IS_SIGNED); @@ -284,7 +280,7 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { } /** - * @deprecated types don't have values + * @deprecated Types don't have values */ @Override @Deprecated 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 cd8ebac54a2..a4c5e01e981 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 @@ -73,6 +73,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; * Algorithms for deducing template arguments in various contexts. */ public class TemplateArgumentDeduction { + private static class TypeOfValueDeducedFromArraySize extends CPPBasicType { + public TypeOfValueDeducedFromArraySize() { + super(ICPPBasicType.Kind.eInt, 0); + } + } + /** * Deduce arguments for a template function from the template id and the template function * parameters. @@ -194,8 +200,16 @@ public class TemplateArgumentDeduction { IType type1 = ((ICPPTemplateNonTypeParameter) tpar).getType(); type1= CPPTemplates.instantiateType(type1, map, -1, null, point); IType type2= arg.getTypeOfNonTypeValue(); - if (!type1.isSameType(type2)) + // Template-argument deduced from an array bound may be of any integral + // type. + if (type2 instanceof TypeOfValueDeducedFromArraySize && + type1 instanceof IBasicType && + ((IBasicType) type1).getKind() == IBasicType.Kind.eInt) { + arg = new CPPTemplateNonTypeArgument(arg.getNonTypeValue(), type1); + deduct.fDeducedArgs.put(tpar, arg); + } else if (!type1.isSameType(type2)) { return false; + } } } } @@ -737,11 +751,7 @@ public class TemplateArgumentDeduction { if (parID >= 0) { ICPPTemplateArgument old= fDeducedArgs.getArgument(parID, fPackOffset); if (old == null) { - // Template-argument deduced from an array bound may be of any integral - // type (14.8.2.5 - 17). - CPPBasicType wildcardIntegralType = - new CPPBasicType(ICPPBasicType.Kind.eInt, CPPBasicType.UNSPECIFIED_MODIFIERS); - if (!deduce(parID, new CPPTemplateNonTypeArgument(as, wildcardIntegralType))) { + if (!deduce(parID, new CPPTemplateNonTypeArgument(as, new TypeOfValueDeducedFromArraySize()))) { return false; } } else if (!as.equals(old.getNonTypeValue())) {