Demonstrate promotion's to unsigned_int<> when one operand is an unsigned_int<> that isn't smaller than the other signed_int<> operand.
The test function check_signed( n ) return's +/- the number of unsigned's that make up its argument the value is negative for signed_int<> and positive for unsigned_int<>.
sint2t a = -1; uint4t b = 3; int i = check_signed( a + b ); b = a + b; CMPCHECK( i, ==, 4 ); CMPCHECK( b, ==, 2 ); uint2t c = 3; i = check_signed( a + c ); b = a + c; CMPCHECK( i, ==, 2 ); CMPCHECK( b, ==, 2 ); uint1t d = 3; i = check_signed( a + d ); b = a + d; CMPCHECK( i, ==, -2 ); CMPCHECK( b, ==, 2 );
Test Result: msvc71 *Failed*, gcc34 Passed, msvc80 Passed
Error
[included]/uint-promotion-id-add.obj:0: (linker) : unresolved external symbol "public: __thiscall imp::signed_int_s::signed_int<64>::operator<class imp::unsigned_int_s::unsigned_int<64> > class imp::unsigned_int_s::unsigned_int<64>(void)const " (??$?BV?$unsigned_int@$0EA@@unsigned_int_s@imp@@@?$signed_int@$0EA@@signed_int_s@imp@@QBE?AV?$unsigned_int@$0EA@@unsigned_int_s@2@XZ) referenced in function "class imp::unsigned_int_s::unsigned_int<64> __cdecl imp::unsigned_int_s::operator+<64,class imp::signed_int_s::signed_int<64> >(class imp::signed_int_s::signed_int<64> const &,class imp::unsigned_int_s::unsigned_int<64> const &)" (??$?H$0EA@V?$signed_int@$0EA@@signed_int_s@imp@@@unsigned_int_s@imp@@YA?AV?$unsigned_int@$0EA@@01@ABV?$signed_int@$0EA@@signed_int_s@1@ABV201@@Z) [included]/uint-promotion-id-add.obj:0: (linker) : unresolved external symbol "public: __thiscall imp::unsigned_int_s::unsigned_int<32>::operator<class imp::signed_int_s::signed_int<64> > class imp::signed_int_s::signed_int<64>(void)const " (??$?BV?$signed_int@$0EA@@signed_int_s@imp@@@?$unsigned_int@$0CA@@unsigned_int_s@imp@@QBE?AV?$signed_int@$0EA@@signed_int_s@2@XZ) referenced in function "class imp::signed_int_s::signed_int<64> __cdecl imp::signed_int_s::operator+<64,class imp::unsigned_int_s::unsigned_int<32> >(class imp::signed_int_s::signed_int<64> const &,class imp::unsigned_int_s::unsigned_int<32> const &)" (??$?H$0EA@V?$unsigned_int@$0CA@@unsigned_int_s@imp@@@signed_int_s@imp@@YA?AV?$signed_int@$0EA@@01@ABV201@ABV?$unsigned_int@$0CA@@unsigned_int_s@1@@Z) [included]/uint-promotion-id-add.obj:0: (linker) : unresolved external symbol "public: __thiscall imp::signed_int_s::signed_int<64>::operator<class imp::unsigned_int_s::unsigned_int<128> > class imp::unsigned_int_s::unsigned_int<128>(void)const " (??$?BV?$unsigned_int@$0IA@@unsigned_int_s@imp@@@?$signed_int@$0EA@@signed_int_s@imp@@QBE?AV?$unsigned_int@$0IA@@unsigned_int_s@2@XZ) referenced in function "class imp::unsigned_int_s::unsigned_int<128> __cdecl imp::unsigned_int_s::operator+<128,class imp::signed_int_s::signed_int<64> >(class imp::signed_int_s::signed_int<64> const &,class imp::unsigned_int_s::unsigned_int<128> const &)" (??$?H$0IA@V?$signed_int@$0EA@@signed_int_s@imp@@@unsigned_int_s@imp@@YA?AV?$unsigned_int@$0IA@@01@ABV?$signed_int@$0EA@@signed_int_s@1@ABV201@@Z) d:\User\C++\imp\src\signed_int\unitdoc\gensrc\uint-promotion-id-add-msvc71.exe : fatal error LNK1120: 3 unresolved externals
This test is the basis of the:
PROMOTION_TEST( op, signed_value, unsiged_value )
macro used in subsiquent tests, where op = +, signed_value = -1 and unsigned_value = 3.
sint2t a = -1; uint4t b = 3, b_msvc_instantiate_conversion_op = a; int i = check_signed( a + b ); b = a + b; CMPCHECK( i, ==, 4 ); CMPCHECK( b, ==, 2 ); uint2t c = 3, c_msvc_instantiate_conversion_op = a; i = check_signed( a + c ); b = a + c; CMPCHECK( i, ==, 2 ); CMPCHECK( b, ==, 2 ); uint1t d = 3; sint2t d_msvc_instantiate_conversion_op = d; i = check_signed( a + d ); b = a + d; CMPCHECK( i, ==, -2 ); CMPCHECK( b, ==, 2 );
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
Ok: i(=4) == 4(=4) Ok: b(=2) == 2(=2) Ok: i(=2) == 2(=2) Ok: b(=2) == 2(=2) Ok: i(=-2) == -2(=-2) Ok: b(=2) == 2(=2) Ok
See (MSVC workaround) for a description of PROMOTION_TEST( ... ).
PROMOTION_TEST( -, -2, 3 )
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
Ok: i(=4) == 4(=4) Ok: u4(=340282366920938463463374607431768211451) == ((-2) - (3))(=-5) Ok: i(=2) == 2(=2) Ok: u2(=18446744073709551611) == ((-2) - (3))(=-5) Ok: i(=-2) == -2(=-2) Ok: s2(=-5) == ((-2) - (3))(=-5) Ok
See (MSVC workaround) for a description of PROMOTION_TEST( ... ).
PROMOTION_TEST( *, -2, 3 )
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
Ok: i(=4) == 4(=4) Ok: u4(=340282366920938463463374607431768211450) == ((-2) * (3))(=-6) Ok: i(=2) == 2(=2) Ok: u2(=18446744073709551610) == ((-2) * (3))(=-6) Ok: i(=-2) == -2(=-2) Ok: s2(=-6) == ((-2) * (3))(=-6) Ok
See (MSVC workaround) for a description of PROMOTION_TEST( ... ).
Positive arguments only are used here as signed devision has implementation-defined results for negative values.
PROMOTION_TEST( /, 30, 3 )
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
Ok: i(=4) == 4(=4) Ok: u4(=10) == ((30) / (3))(=10) Ok: i(=2) == 2(=2) Ok: u2(=10) == ((30) / (3))(=10) Ok: i(=-2) == -2(=-2) Ok: s2(=10) == ((30) / (3))(=10) Ok
See (MSVC workaround) for a description of PROMOTION_TEST( ... ).
Positive arguments only are used here as signed devision has implementation-defined results for negative values.
PROMOTION_TEST( %, 36, 3 )
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
Ok: i(=4) == 4(=4) Ok: u4(=0) == ((36) % (3))(=0) Ok: i(=2) == 2(=2) Ok: u2(=0) == ((36) % (3))(=0) Ok: i(=-2) == -2(=-2) Ok: s2(=0) == ((36) % (3))(=0) Ok
See (MSVC workaround) for a description of PROMOTION_TEST( ... ).
PROMOTION_TEST( &, -2, 3 )
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
Ok: i(=4) == 4(=4) Ok: u4(=2) == ((-2) & (3))(=2) Ok: i(=2) == 2(=2) Ok: u2(=2) == ((-2) & (3))(=2) Ok: i(=-2) == -2(=-2) Ok: s2(=2) == ((-2) & (3))(=2) Ok
See (MSVC workaround) for a description of PROMOTION_TEST( ... ).
PROMOTION_TEST( |, -2, 3 )
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
Ok: i(=4) == 4(=4) Ok: u4(=340282366920938463463374607431768211455) == ((-2) | (3))(=-1) Ok: i(=2) == 2(=2) Ok: u2(=18446744073709551615) == ((-2) | (3))(=-1) Ok: i(=-2) == -2(=-2) Ok: s2(=-1) == ((-2) | (3))(=-1) Ok
See (MSVC workaround) for a description of PROMOTION_TEST( ... ).
PROMOTION_TEST( ^, -2, 3 )
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
Ok: i(=4) == 4(=4) Ok: u4(=340282366920938463463374607431768211453) == ((-2) ^ (3))(=-3) Ok: i(=2) == 2(=2) Ok: u2(=18446744073709551613) == ((-2) ^ (3))(=-3) Ok: i(=-2) == -2(=-2) Ok: s2(=-3) == ((-2) ^ (3))(=-3) Ok