mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Type comparison of default ints, bug 270275.
This commit is contained in:
parent
23e918bc08
commit
3546025271
3 changed files with 28 additions and 9 deletions
|
@ -1667,6 +1667,23 @@ public class AST2Tests extends AST2BaseTest {
|
|||
}
|
||||
}
|
||||
|
||||
// int plainInt = 7;
|
||||
// signed int signedInt = -2;
|
||||
// unsigned int unsignedInt = 99;
|
||||
// noSpec= 12;
|
||||
public void testBug270275_int_is_equivalent_to_signed_int() throws Exception {
|
||||
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C);
|
||||
IASTDeclaration[] declarations = tu.getDeclarations();
|
||||
IType plainInt = ((IVariable)((IASTSimpleDeclaration)declarations[0]).getDeclarators()[0].getName().resolveBinding()).getType();
|
||||
IType signedInt = ((IVariable)((IASTSimpleDeclaration)declarations[1]).getDeclarators()[0].getName().resolveBinding()).getType();
|
||||
IType unsignedInt = ((IVariable)((IASTSimpleDeclaration)declarations[2]).getDeclarators()[0].getName().resolveBinding()).getType();
|
||||
IType noSpec = ((IVariable)((IASTSimpleDeclaration)declarations[3]).getDeclarators()[0].getName().resolveBinding()).getType();
|
||||
assertTrue(plainInt.isSameType(signedInt));
|
||||
assertFalse(plainInt.isSameType(unsignedInt));
|
||||
assertFalse(signedInt.isSameType(unsignedInt));
|
||||
assertTrue(plainInt.isSameType(noSpec));
|
||||
}
|
||||
|
||||
// struct A {} a1;
|
||||
// typedef struct A * AP;
|
||||
// struct A * const a2;
|
||||
|
|
|
@ -127,14 +127,16 @@ public class CBasicType implements ICBasicType {
|
|||
|
||||
CBasicType cObj = (CBasicType)obj;
|
||||
|
||||
return (cObj.getType() == this.getType()
|
||||
&& cObj.isLong() == this.isLong()
|
||||
&& cObj.isShort() == this.isShort()
|
||||
&& cObj.isSigned() == this.isSigned()
|
||||
&& cObj.isUnsigned() == this.isUnsigned()
|
||||
&& cObj.isLongLong() == this.isLongLong()
|
||||
&& cObj.isComplex() == this.isComplex()
|
||||
&& cObj.isImaginary() == this.isImaginary());
|
||||
if (type != cObj.type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type == IBasicType.t_int) {
|
||||
//signed int and int are equivalent
|
||||
return (qualifiers & ~IS_SIGNED) == (cObj.qualifiers & ~IS_SIGNED);
|
||||
} else {
|
||||
return (qualifiers == cObj.qualifiers);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -64,7 +64,7 @@ public class CPPBasicType implements ICPPBasicType {
|
|||
//signed int and int are equivalent
|
||||
return (qualifierBits & ~IS_SIGNED) == (t.qualifierBits & ~IS_SIGNED);
|
||||
}
|
||||
return (type == t.type && qualifierBits == t.qualifierBits);
|
||||
return qualifierBits == t.qualifierBits;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
Loading…
Add table
Reference in a new issue