top | item 17787935

(no title)

catamorphismic | 7 years ago

Wouldn't the better solution be having compiler support for rejecting compilation of constructs that have UB?

discuss

order

the_why_of_y|7 years ago

  int add(int a, int b)
  {
    return a + b;
  }
Do you want the compiler to reject this because (assuming it has external linkage) there's no guarantee that there is no call with arguments such that the addition would overflow?

iforgotpassword|7 years ago

This discussion came up recently, but my stance still is that if you know for sure at compile time that some code always results in UB or is just non-conforming, you should not fuck around and just remove a big chunk of code because the standard allows you so, but either simply refuse compilation (my preference) or at least still just emit code representing what was written (effectively the implementation defined behavior route).