digitalmars.D - TDPL error or compiler bug?
- Timon Gehr (10/10) Sep 04 2011 static assert(0xF234_5678_9ABC_5A5AUL == 17452669531959614042UL);
- Jonathan M Davis (6/19) Sep 04 2011 It sounds like the compiler assumes that a hexadecimal literal is unsign...
- Timon Gehr (5/24) Sep 04 2011 Note that
static assert(0xF234_5678_9ABC_5A5AUL == 17452669531959614042UL); auto a = 0xF234_5678_9ABC_5A5AL; // ok, type is ulong auto b = 17452669531959614042L; // error, signed integer overflow But p33. in TDPL states: "To write a hexadecimal integral literal, use the prefix 0x or 0X followed by a sequence of the letters 0-9, a-f, A-F, or _. [...] All of these literals can be suffixed similarly to the decimal constants, and the rules governing their types are identical to those for decimal literals." Is this a compiler bug or an error in TDPL?
Sep 04 2011
On Sunday, September 04, 2011 22:59:21 Timon Gehr wrote:static assert(0xF234_5678_9ABC_5A5AUL == 17452669531959614042UL); auto a = 0xF234_5678_9ABC_5A5AL; // ok, type is ulong auto b = 17452669531959614042L; // error, signed integer overflow But p33. in TDPL states: "To write a hexadecimal integral literal, use the prefix 0x or 0X followed by a sequence of the letters 0-9, a-f, A-F, or _. [...] All of these literals can be suffixed similarly to the decimal constants, and the rules governing their types are identical to those for decimal literals." Is this a compiler bug or an error in TDPL?It sounds like the compiler assumes that a hexadecimal literal is unsigned and that a decimal literal is signed - which is what I would have expected it to do. TDPL should probably be changed. But maybe Walter or Andrei has a different opinion on that. - Jonathan M Davis
Sep 04 2011
On 09/04/2011 11:05 PM, Jonathan M Davis wrote:On Sunday, September 04, 2011 22:59:21 Timon Gehr wrote:Note that static assert(is(typeof(0x1234_5678_9ABC_5A5AL)==long)); The signedness of hex literals depends on whether or not the value fits in the signed type.static assert(0xF234_5678_9ABC_5A5AUL == 17452669531959614042UL); auto a = 0xF234_5678_9ABC_5A5AL; // ok, type is ulong auto b = 17452669531959614042L; // error, signed integer overflow But p33. in TDPL states: "To write a hexadecimal integral literal, use the prefix 0x or 0X followed by a sequence of the letters 0-9, a-f, A-F, or _. [...] All of these literals can be suffixed similarly to the decimal constants, and the rules governing their types are identical to those for decimal literals." Is this a compiler bug or an error in TDPL?It sounds like the compiler assumes that a hexadecimal literal is unsigned and that a decimal literal is signed - which is what I would have expected it to do. TDPL should probably be changed. But maybe Walter or Andrei has a different opinion on that. - Jonathan M Davis
Sep 04 2011