Bug in ^^
Vladimir Panteleev
thecybershadow.lists at gmail.com
Tue Sep 17 16:49:46 UTC 2019
On Tuesday, 17 September 2019 at 01:53:12 UTC, Brett wrote:
> 10^^16 = 1874919424 ???
>
> 10L^^16 is valid, but
>
> enum x = 10^^16 gives wrong value.
>
> I didn't catch this ;/
The same can be observed with multiplication:
// This compiles, but the result is "non-sensical" due to oveflow.
enum n = 1_000_000 * 1_000_000;
The same can happen with C:
static const int n = 1000000 * 1000000;
However, C compilers warn about this:
gcc:
test.c:1:30: warning: integer overflow in expression of type
‘int’ results in ‘-727379968’ [-Woverflow]
1 | static const int n = 1000000 * 1000000;
| ^
clang:
test.c:1:30: warning: overflow in expression; result is
-727379968 with type 'int' [-Winteger-overflow]
static const int n = 1000000 * 1000000;
^
1 warning generated.
I think D should warn about any overflows which happen at
compile-time too.
More information about the Digitalmars-d
mailing list