From 6d81f014764e3bb9452d3697b84093bed0668f02 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 17 Sep 2019 12:13:19 -0400 Subject: Don't assume char is signed in int conversion tests (fixes #361) --- libtests/qintc.cc | 11 +++++++---- libtests/qtest/qintc/qintc.out | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'libtests') diff --git a/libtests/qintc.cc b/libtests/qintc.cc index 53ec3772..6b35e837 100644 --- a/libtests/qintc.cc +++ b/libtests/qintc.cc @@ -32,12 +32,13 @@ int main() uint64_t ul1 = 1099511627776LL; // Too big for 32-bit uint64_t ul2 = 12345; // Fits into 32-bit int32_t i2 = 81; // Fits in char and uchar - char c1 = '\xf7'; // Signed value when char + signed char c1 = static_cast('\xf7'); // Signed value when char + char c2 = 'W'; // char; may be signed or unsigned // Verify i1 and u1 have same bit pattern assert(static_cast(i1) == u1); - // Verify that we can unsafely convert between char and unsigned char - assert(c1 == static_cast(static_cast(c1))); + // Verify that we can unsafely convert between signed and unsigned char + assert(c1 == static_cast(static_cast(c1))); try_convert(true, QIntC::to_int, i1); try_convert(true, QIntC::to_uint, u1); @@ -51,7 +52,9 @@ int main() try_convert(false, QIntC::to_ulonglong, i1); try_convert(true, QIntC::to_char, i2); try_convert(true, QIntC::to_uchar, i2); - try_convert(false, QIntC::to_uchar, c1); + try_convert(false, QIntC::to_uchar, c1); + try_convert(true, QIntC::to_uchar, c2); + try_convert(true, QIntC::to_char, c2); return 0; } diff --git a/libtests/qtest/qintc/qintc.out b/libtests/qtest/qintc/qintc.out index 5c6479e2..2a2ff9f5 100644 --- a/libtests/qtest/qintc/qintc.out +++ b/libtests/qtest/qintc/qintc.out @@ -10,4 +10,6 @@ QIntC::to_offset(i1): -1153374643 -1153374643 PASSED QIntC::to_ulonglong(i1): integer out of range converting -1153374643 from a 4-byte signed type to a 8-byte unsigned type PASSED QIntC::to_char(i2): 81 Q PASSED QIntC::to_uchar(i2): 81 Q PASSED -QIntC::to_uchar(c1): integer out of range converting ÷ from a 1-byte signed type to a 1-byte unsigned type PASSED +QIntC::to_uchar(c1): integer out of range converting ÷ from a 1-byte signed type to a 1-byte unsigned type PASSED +QIntC::to_uchar(c2): W W PASSED +QIntC::to_char(c2): W W PASSED -- cgit v1.2.3-54-g00ecf