1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Bug 394024 - Template resolution problem with unsigned int non type

parameter. A better fix.
This commit is contained in:
Sergey Prigogin 2012-11-12 11:21:32 -08:00
parent 9f8f8035d2
commit 1974b13a88
2 changed files with 17 additions and 11 deletions

View file

@ -32,7 +32,6 @@ import org.eclipse.core.runtime.CoreException;
*/ */
public class CPPBasicType implements ICPPBasicType, ISerializableType { public class CPPBasicType implements ICPPBasicType, ISerializableType {
private static final int FROM_STRING_LITERAL = 1 << 31; 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 BOOLEAN = new CPPBasicType(Kind.eBoolean, 0, null);
public static final CPPBasicType NULL_PTR = new CPPBasicType(Kind.eNullPtr, 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 modifiers = getModifiers();
int otherModifiers = other.getModifiers(); int otherModifiers = other.getModifiers();
if ((modifiers & UNSPECIFIED_MODIFIERS) != 0 || (otherModifiers & UNSPECIFIED_MODIFIERS) != 0) {
return true;
}
if (fKind == Kind.eInt) { if (fKind == Kind.eInt) {
// Signed int and int are equivalent. // Signed int and int are equivalent.
return (modifiers & ~IS_SIGNED) == (otherModifiers & ~IS_SIGNED); 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 @Override
@Deprecated @Deprecated

View file

@ -73,6 +73,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
* Algorithms for deducing template arguments in various contexts. * Algorithms for deducing template arguments in various contexts.
*/ */
public class TemplateArgumentDeduction { 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 * Deduce arguments for a template function from the template id and the template function
* parameters. * parameters.
@ -194,8 +200,16 @@ public class TemplateArgumentDeduction {
IType type1 = ((ICPPTemplateNonTypeParameter) tpar).getType(); IType type1 = ((ICPPTemplateNonTypeParameter) tpar).getType();
type1= CPPTemplates.instantiateType(type1, map, -1, null, point); type1= CPPTemplates.instantiateType(type1, map, -1, null, point);
IType type2= arg.getTypeOfNonTypeValue(); 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; return false;
}
} }
} }
} }
@ -737,11 +751,7 @@ public class TemplateArgumentDeduction {
if (parID >= 0) { if (parID >= 0) {
ICPPTemplateArgument old= fDeducedArgs.getArgument(parID, fPackOffset); ICPPTemplateArgument old= fDeducedArgs.getArgument(parID, fPackOffset);
if (old == null) { if (old == null) {
// Template-argument deduced from an array bound may be of any integral if (!deduce(parID, new CPPTemplateNonTypeArgument(as, new TypeOfValueDeducedFromArraySize()))) {
// type (14.8.2.5 - 17).
CPPBasicType wildcardIntegralType =
new CPPBasicType(ICPPBasicType.Kind.eInt, CPPBasicType.UNSPECIFIED_MODIFIERS);
if (!deduce(parID, new CPPTemplateNonTypeArgument(as, wildcardIntegralType))) {
return false; return false;
} }
} else if (!as.equals(old.getNonTypeValue())) { } else if (!as.equals(old.getNonTypeValue())) {