From dc8313b30436145d8b542ac4c9f4151c1c8ff874 Mon Sep 17 00:00:00 2001 From: "Igor V. Kovalenko" Date: Mon, 30 Jan 2023 19:42:29 +0300 Subject: [PATCH] Add another integer conversion test for issue 265 Bug: https://github.com/eclipse-cdt/cdt/issues/265 --- .../core/parser/tests/ast2/AST2CPPTests.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index b22af681248..a3cbab3ec2b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -13821,4 +13821,28 @@ public void testNullPointerConstantConversion_573764() throws Exception { // Invalid argument (not null pointer constant) assertTrue(collector.getName(callIndexStart + 13).resolveBinding() instanceof IProblemBinding); } + + // template + // constexpr bool calculate(SignedType x, UnsignedType y) { + // if (sizeof(x) == sizeof(y)) { + // return x - y >= 0; + // } else { + // return true; + // } + // } + // + // constexpr auto test_32 = calculate(1, 2); + // constexpr auto test_64 = calculate(1, 2); + public void testArithmeticConversionIssue_265() throws Exception { + // Depending on size of integer types above it may happen that the rank of unsigned type operand + // is less than rank of signed type operand, and both types are of same size. + // If so the conversion is to unsigned integer type corresponding to the type of the operand + // with signed integer type, and calculated result cannot be less than zero - check it. + // 32-bit case used to fail with signed long and unsigned int, + // 64-bit case used to fail with signed long long and unsigned long. + parseAndCheckBindings(); + BindingAssertionHelper helper = getAssertionHelper(); + helper.assertVariableValue("test_32", 1); + helper.assertVariableValue("test_64", 1); + } }