A strange div bug on Linux x86_64, (both dmd & ldc2): long -5000 / size_t 2 = 9223372036854773308

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Aug 17 11:15:20 UTC 2020

On 8/13/20 9:40 AM, FeepingCreature wrote:
> On Thursday, 13 August 2020 at 13:33:19 UTC, bachmeier wrote:
>> That's why that behavior needs to be changed as well. It's horrible to 
>> implicitly cast from int to double when doing so results in obviously 
>> wrong behavior. Hopefully there won't be any more talk about safe by 
>> default as long as the language has features like this that are 
>> obviously broken and trivially fixed.
> It's not trivially fixed. :-(
> I added a check for this case in DMD, just to see, and it breaks Phobos 
> all over. Anything that interfaces to C with more complicated struct 
> types does division with mixed signs. There'd need to be a lot of casts 
> added as a result of changing this.

Maybe a solution would be to only reject code with integrals statically 
knoen to be negative that are converted to unsigned integrals. Most of 
those are arguably bugs.

More information about the Digitalmars-d mailing list