summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hornsey <hornseyf@objectcomputing.com>2021-07-01 14:41:42 -0500
committerFred Hornsey <hornseyf@objectcomputing.com>2021-07-08 19:27:53 -0500
commit1655769f404204483e8ee28a686f765df332be71 (patch)
tree4ca11fe7a6031075a416096c8eefdf581280d064
parent90531b1dd0bcf226497542cd414c4a3b03456c10 (diff)
downloadATCD-1655769f404204483e8ee28a686f765df332be71.tar.gz
Fix Integer Literals for Windows
-rw-r--r--TAO/TAO_IDL/be/be_helper.cpp42
-rw-r--r--TAO/TAO_IDL/be/be_union_branch.cpp4
-rw-r--r--TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp4
-rw-r--r--TAO/tests/IDLv4/explicit_ints/main.cpp4
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 ac8c0735c0c..98f1f0e3649 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 <typename IntType>
+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<ACE_CDR::Long> (
+ *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<ACE_CDR::LongLong> (
+ *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 372bf6be834..ec8442d5f43 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 f172a2f7d82..f1ac4e6e0f2 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 cff84c84463..7aaa38a8d9c 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<CORBA::Int16> (any_failed, "i16_min", i16_min, -32768);
expect_equals<CORBA::Int16> (any_failed, "i16_max", i16_max, 32767);
expect_equals<CORBA::UInt32> (any_failed, "u32_max", u32_max, 4294967295);
- expect_equals<CORBA::Int32> (any_failed, "i32_min", i32_min, -2147483648);
+ expect_equals<CORBA::Int32> (any_failed, "i32_min", i32_min, -2147483647 - 1);
expect_equals<CORBA::Int32> (any_failed, "i32_max", i32_max, 2147483647);
expect_equals<CORBA::UInt64> (any_failed, "u64_max", u64_max, 18446744073709551615ULL);
- expect_equals<CORBA::Int64> (any_failed, "i64_min", i64_min, (-9223372036854775807 - 1));
+ expect_equals<CORBA::Int64> (any_failed, "i64_min", i64_min, -9223372036854775807 - 1);
expect_equals<CORBA::Int64> (any_failed, "i64_max", i64_max, 9223372036854775807);
expect_equals<CORBA::UInt8> (any_failed, "u8_min_overflow", u8_min_overflow, u8_max);