Signed integer overflow undefined behavior or not?

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 12 22:46:36 PST 2015


On 11/12/2015 10:00 PM, Walter Bright wrote:
 > On 11/12/2015 4:43 PM, Ali Çehreli wrote:
 >> So the question is, do we support twos complement only, hence signed
 >> overflow is
 >> defined as wrap,
 >
 > Yes. I see no reason to support 1's complement.

It's official! :)

 > It's worth checking how LDC and GDC deal with this deep in their
 > optimizer - is it considering it undefined behavior?

Since it's UB in C and C++, I've heard that both clang and gcc do remove 
code branches if they can prove that there will be signed overflow. I 
don't know how or whether that optimization is turned off for D.

Ali



More information about the Digitalmars-d mailing list