From 1655769f404204483e8ee28a686f765df332be71 Mon Sep 17 00:00:00 2001 From: Fred Hornsey Date: Thu, 1 Jul 2021 14:41:42 -0500 Subject: [PATCH] Fix Integer Literals for Windows --- TAO/TAO_IDL/be/be_helper.cpp | 42 +++++++++++-------- TAO/TAO_IDL/be/be_union_branch.cpp | 4 +- .../be/be_visitor_union/discriminant_ci.cpp | 4 +- TAO/tests/IDLv4/explicit_ints/main.cpp | 4 +- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/TAO/TAO_IDL/be/be_helper.cpp b/TAO/TAO_IDL/be/be_helper.cpp index ac8c0735c0cca..98f1f0e364938 100644 --- a/TAO/TAO_IDL/be/be_helper.cpp +++ b/TAO/TAO_IDL/be/be_helper.cpp @@ -499,6 +499,26 @@ TAO_OutStream::print (UTL_IdList *idl) return *this; } +template +void +signed_int_helper (TAO_OutStream &os, IntType value, IntType min, const char *specifier) +{ + /* + * It seems that in C/C++ the minus sign and the bare number are parsed + * separately for negative integer literals. This can cause compilers + * to complain when using the minimum value of a signed integer because + * the number without the minus sign is 1 past the max signed value. + * + * https://stackoverflow.com/questions/65007935 + * + * Apparently the workaround is to write it as `VALUE_PLUS_ONE - 1`. + */ + const bool min_value = value == min; + if (min_value) ++value; + os.print (specifier, value); + if (min_value) os.print (" - 1"); +} + TAO_OutStream& TAO_OutStream::print (AST_Expression *expr) { @@ -523,30 +543,16 @@ TAO_OutStream::print (AST_Expression *expr) this->TAO_OutStream::print (ACE_INT32_FORMAT_SPECIFIER_ASCII "%c", ev->u.usval, 'U'); break; case AST_Expression::EV_long: - this->TAO_OutStream::print (ACE_INT32_FORMAT_SPECIFIER_ASCII, ev->u.lval); + signed_int_helper ( + *this, ev->u.lval, ACE_INT32_MIN, ACE_INT32_FORMAT_SPECIFIER_ASCII); break; case AST_Expression::EV_ulong: this->TAO_OutStream::print (ACE_UINT32_FORMAT_SPECIFIER_ASCII "%c", ev->u.ulval, 'U'); break; case AST_Expression::EV_longlong: this->TAO_OutStream::print ("ACE_INT64_LITERAL ("); - { - ACE_CDR::LongLong value = ev->u.llval; - /* - * It seems that in C/C++ the minus sign and the bare number are parsed - * separately for negative integer literals. This can cause compilers - * to complain when using the minimum value of a signed integer because - * the number without the minus sign is 1 past the max signed value. - * - * https://stackoverflow.com/questions/65007935 - * - * Apparently the workaround is to write it as `VALUE_PLUS_ONE - 1`. - */ - const bool min_value = value == ACE_INT64_MIN; - if (min_value) ++value; - TAO_OutStream::print (ACE_INT64_FORMAT_SPECIFIER_ASCII, value); - if (min_value) TAO_OutStream::print (" - 1"); - } + signed_int_helper ( + *this, ev->u.llval, ACE_INT64_MIN, ACE_INT64_FORMAT_SPECIFIER_ASCII); this->TAO_OutStream::print (")"); break; case AST_Expression::EV_ulonglong: diff --git a/TAO/TAO_IDL/be/be_union_branch.cpp b/TAO/TAO_IDL/be/be_union_branch.cpp index 372bf6be83449..ec8442d5f4350 100644 --- a/TAO/TAO_IDL/be/be_union_branch.cpp +++ b/TAO/TAO_IDL/be/be_union_branch.cpp @@ -118,11 +118,9 @@ be_union_branch::gen_default_label_value (TAO_OutStream *os, switch (bu->udisc_type ()) { case AST_Expression::EV_short: - case AST_Expression::EV_int8: *os << dv.u.short_val; break; case AST_Expression::EV_ushort: - case AST_Expression::EV_uint8: *os << dv.u.ushort_val; break; case AST_Expression::EV_long: @@ -133,6 +131,8 @@ be_union_branch::gen_default_label_value (TAO_OutStream *os, break; case AST_Expression::EV_octet: case AST_Expression::EV_char: + case AST_Expression::EV_int8: + case AST_Expression::EV_uint8: os->print ("'\\%o'", dv.u.char_val); break; case AST_Expression::EV_bool: diff --git a/TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp b/TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp index f172a2f7d82f1..f1ac4e6e0f219 100644 --- a/TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp +++ b/TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp @@ -159,11 +159,9 @@ be_visitor_union_discriminant_ci::visit_predefined_type ( switch (bu->udisc_type ()) { case AST_Expression::EV_short: - case AST_Expression::EV_int8: *os << dv.u.short_val; break; case AST_Expression::EV_ushort: - case AST_Expression::EV_uint8: *os << dv.u.ushort_val; break; case AST_Expression::EV_long: @@ -174,6 +172,8 @@ be_visitor_union_discriminant_ci::visit_predefined_type ( break; case AST_Expression::EV_char: case AST_Expression::EV_octet: + case AST_Expression::EV_int8: + case AST_Expression::EV_uint8: os->print ("'\\%o'", dv.u.char_val); break; case AST_Expression::EV_bool: diff --git a/TAO/tests/IDLv4/explicit_ints/main.cpp b/TAO/tests/IDLv4/explicit_ints/main.cpp index cff84c84463ea..7aaa38a8d9c22 100644 --- a/TAO/tests/IDLv4/explicit_ints/main.cpp +++ b/TAO/tests/IDLv4/explicit_ints/main.cpp @@ -42,10 +42,10 @@ ACE_TMAIN (int, ACE_TCHAR *[]) expect_equals (any_failed, "i16_min", i16_min, -32768); expect_equals (any_failed, "i16_max", i16_max, 32767); expect_equals (any_failed, "u32_max", u32_max, 4294967295); - expect_equals (any_failed, "i32_min", i32_min, -2147483648); + expect_equals (any_failed, "i32_min", i32_min, -2147483647 - 1); expect_equals (any_failed, "i32_max", i32_max, 2147483647); expect_equals (any_failed, "u64_max", u64_max, 18446744073709551615ULL); - expect_equals (any_failed, "i64_min", i64_min, (-9223372036854775807 - 1)); + expect_equals (any_failed, "i64_min", i64_min, -9223372036854775807 - 1); expect_equals (any_failed, "i64_max", i64_max, 9223372036854775807); expect_equals (any_failed, "u8_min_overflow", u8_min_overflow, u8_max);