3 ms·
> The problem is the code unconditionally dereferences the pointer, which would be UB if it was a null pointer. Only when NDEBUG is defined, right?
by aw1621107 7mo ago
> The problem is the code unconditionally dereferences the pointer, which would be UB if it was a null pointer.
Only when NDEBUG is defined, right?
- saagarjha 7mo agoNo, the code that does this is always active
- gottheUIblues 7mo agoRight so strictly speaking C++ could do anything here when passed a null pointer, because even though assert terminates the program, the C++ compiler cannot see that, and there is then undefined behaviour in that case
- aw1621107 7mo ago> because even though assert terminates the program, the C++ compiler cannot see that I think it should be able to. I'm pretty sure assert is defined to call abort when triggered and abort is tagged with [[noreturn]], so the compiler knows control flow isn't coming back.
- aw1621107 7mo agoShouldn't control flow diverge if the assert is triggered when NDEBUG is not defined? Pretty sure assert is defined to call abort when triggered and that is tagged [[noreturn]].
- saagarjha 7mo agoSorry, yes, I misread you