DeVault: Announcing the Hare programming language
DeVault: Announcing the Hare programming language
Posted May 5, 2022 18:10 UTC (Thu) by farnz (subscriber, #17727)In reply to: DeVault: Announcing the Hare programming language by nybble41
Parent article: DeVault: Announcing the Hare programming language
I'm not sure I follow your reasoning, and I'd appreciate you expanding on it.
Take the following C++ code:
bool bad_code(bool deref_null) {
int *foo;
int real_val;
int *bar = deref_null ? nullptr : ℜ_val;
*bar = 0;
return bar == nullptr;
}
I don't see how the snippets you've quoted make it impossible for this function's return value to differ from its deref_null parameter. The null pointer remains a unique value; the behaviour of *bar = 0 is undefined, but importantly, if I remove that line, the function behaves the same in both ISO C++ and C++ with -fno-delete-null-pointer-checks - the distinction is that in ISO C++, this function can be optimized to the equivalent of:
bool bad_code(bool) { return false; }
while with -fno-delete-null-pointer-checks, it can only be optimized to:
bool bad_code(bool deref_null) { return deref_null; }
Although, in both cases, it's perfectly reasonable to elide or not elide the write to pointer value 0, since that write is UB.
