mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-07 09:05:24 +02:00
Bug 394024 - Template resolution problem with unsigned int non type
parameter.
This commit is contained in:
parent
5b038020f5
commit
dd9ba663b4
3 changed files with 28 additions and 9 deletions
|
@ -4205,8 +4205,18 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
// S(a);
|
// S(a);
|
||||||
// }
|
// }
|
||||||
public void testFunctionTemplateWithArrayReferenceParameter_269926() throws Exception {
|
public void testFunctionTemplateWithArrayReferenceParameter_269926() throws Exception {
|
||||||
final String code = getAboveComment();
|
parseAndCheckBindings();
|
||||||
parseAndCheckBindings(code);
|
}
|
||||||
|
|
||||||
|
// template <unsigned int N>
|
||||||
|
// void S(int (&array)[N]);
|
||||||
|
//
|
||||||
|
// int a[1];
|
||||||
|
// void test() {
|
||||||
|
// S(a);
|
||||||
|
// }
|
||||||
|
public void testFunctionTemplateWithArrayReferenceParameter_394024() throws Exception {
|
||||||
|
parseAndCheckBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
// template <typename T>
|
// template <typename T>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2011 IBM Corporation and others.
|
* Copyright (c) 2004, 2012 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Andrew Niefer (IBM Corporation) - initial API and implementation
|
* Andrew Niefer (IBM Corporation) - initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ 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);
|
||||||
|
|
||||||
|
@ -119,16 +121,20 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType {
|
||||||
if (!(object instanceof ICPPBasicType))
|
if (!(object instanceof ICPPBasicType))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ICPPBasicType t = (ICPPBasicType) object;
|
ICPPBasicType other = (ICPPBasicType) object;
|
||||||
if (fKind != t.getKind())
|
if (fKind != other.getKind())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int modifiers = getModifiers();
|
int modifiers = 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) == (t.getModifiers() & ~IS_SIGNED);
|
return (modifiers & ~IS_SIGNED) == (otherModifiers & ~IS_SIGNED);
|
||||||
}
|
}
|
||||||
return modifiers == t.getModifiers();
|
return modifiers == otherModifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -737,8 +737,11 @@ 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) {
|
||||||
if (!deduce(parID,
|
// Template-argument deduced from an array bound may be of any integral
|
||||||
new CPPTemplateNonTypeArgument(as, new CPPBasicType(ICPPBasicType.Kind.eInt, 0)))) {
|
// 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())) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue