diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 8b78a760c6c..d9e3ca824cd 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -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; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java index 3a9cdb91694..fbb00716f76 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java @@ -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 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 0fb977363d8..82e536ef385 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 @@ -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)