C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Standardising 0xdeadbeef for pointers

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Mon, 4 Aug 2025 14:54:02 +0300
On 4 Aug 2025 14:32, Frederick Virchanza Gotham via Std-Proposals wrote:
> On Mon, Aug 4, 2025 at 12:09 PM Andrey Semashev wrote:
>>
>>> You're missing the point. If the above function were to be marked as
>>> 'throw_on_nullptr', and then if the invocation of 'strstr' returns a
>>> nullptr and has 3 added to it, it will throw an exception of type
>>> nullptr_t, rather than segfault when 'libc' inside the implementation
>>> of 'stoul' tries to access the memory address 0x0000000000000003.
>>
>> And what if the argument p was nullptr in the first place?
>
> nullptr_t will be thrown if a nullptr is passed as an argument to any
> function. If you genuinely need to pass a nullptr to a function
> though, you must exempt it:
>
> void Func(char const *const p) throw_on_nullptr
> {
> return SomeOtherFunction( std::exempt(p) );
> }

At this point, why would you be using pointers to begin with?

Received on 2025-08-04 11:54:06