Date: Mon, 10 Feb 2025 16:20:55 -0800
On Monday, 10 February 2025 01:44:22 Pacific Standard Time Tiago Freire via
Std-Proposals wrote:
> > It is not possible to write a valid C++ program, where the address of a
> > reference is the nullptr.
> Never heard of that. I guess that depends on your definition of valid, if
> writing bugs is not a “valid” C++ program, but there’s nothing stopping you
> from writing them.
In order to bind a reference to a nullptr, you must have dereferenced the
nullptr first, so you're already UB before you bound the reference.
The fact that most compilers don't *actually* load from the pointed value and
therefore don't cause a segmentation fault / crash is irrelevant. That's a
possible outcome of UB.
Std-Proposals wrote:
> > It is not possible to write a valid C++ program, where the address of a
> > reference is the nullptr.
> Never heard of that. I guess that depends on your definition of valid, if
> writing bugs is not a “valid” C++ program, but there’s nothing stopping you
> from writing them.
In order to bind a reference to a nullptr, you must have dereferenced the
nullptr first, so you're already UB before you bound the reference.
The fact that most compilers don't *actually* load from the pointed value and
therefore don't cause a segmentation fault / crash is irrelevant. That's a
possible outcome of UB.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel DCAI Platform & System Engineering
Received on 2025-02-11 00:20:59