On Thursday, 31 July 2025 09:41:09 Pacific Daylight Time zxuiji via Std-
Proposals wrote:
> It's still a pointer so it has pointer arithmetic, that's all that matters
> which therefore means it's not UB to use pointer arithmetic on null*ptr *or*
> NULL*
You're missing the point. The program is UB the moment you add a non-zero
displacement to nullptr. UB can manifest in many different ways, including
"behaving exactly as you'd expect" (for any definition of "you" and "expect").
The most likely scenario is that the compiler will emit an addition and result
in a small pointer value around 0x0. But you can't count on it. In an ASan
build, for example, the compiler might have already inserted an escape path
that aborts the execution (https://godbolt.org/z/q84nEaxTT).
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Principal Engineer - Intel Platform & System Engineering
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals