Date: Tue, 5 Aug 2025 17:24:03 +0000
What is a smart-pointer?
That's the Jeopardy answer.
________________________________
From: Std-Proposals <std-proposals-bounces_at_[hidden]> on behalf of Julien Villemure-Fréchette via Std-Proposals <std-proposals_at_[hidden]>
Sent: Tuesday, August 5, 2025 6:57:45 PM
To: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
Cc: Julien Villemure-Fréchette <julien.villemure_at_[hidden]>
Subject: Re: [std-proposals] Standardising 0xdeadbeef for pointers
This raises an an important issue for implementing a "throw_on_nullptr" function: you may only call functions marked with "throw_on_nullptr" within such a function. This limits you to use only APIs that has functions marked as such. To be able to call a function not marked with "throw_on_nullptr", you would still need to ensure (either manually or from invariants implied from source code) that this function is called in contact, and that it wouldn't evaluate an access through a null pointer value, and if it would evaluate through a null pointer value, then manually throw before attempting to call it. Even then, the function could have a bug and actually evaluate an access through a null pointer value even when called in contract, in which case the function would not be throwing an exception and you would end up violating the "throw_on_nullptr" speciation: this would in itself lead to a UB, on top a the UB of evaluating the access through the null pointer value.
On August 3, 2025 10:48:08 a.m. EDT, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> wrote:
I'm going off on a tangent here, but imagine if we could mark a function (or lambda) as follows:
int Func(double) throw_on_nullptr
{
. . .
}
If you try to dereference a nullptr in this function, or if you perform addition or subtraction on a nullptr, it throws std::nullptr_t.
Maybe?
That's the Jeopardy answer.
________________________________
From: Std-Proposals <std-proposals-bounces_at_[hidden]> on behalf of Julien Villemure-Fréchette via Std-Proposals <std-proposals_at_[hidden]>
Sent: Tuesday, August 5, 2025 6:57:45 PM
To: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
Cc: Julien Villemure-Fréchette <julien.villemure_at_[hidden]>
Subject: Re: [std-proposals] Standardising 0xdeadbeef for pointers
This raises an an important issue for implementing a "throw_on_nullptr" function: you may only call functions marked with "throw_on_nullptr" within such a function. This limits you to use only APIs that has functions marked as such. To be able to call a function not marked with "throw_on_nullptr", you would still need to ensure (either manually or from invariants implied from source code) that this function is called in contact, and that it wouldn't evaluate an access through a null pointer value, and if it would evaluate through a null pointer value, then manually throw before attempting to call it. Even then, the function could have a bug and actually evaluate an access through a null pointer value even when called in contract, in which case the function would not be throwing an exception and you would end up violating the "throw_on_nullptr" speciation: this would in itself lead to a UB, on top a the UB of evaluating the access through the null pointer value.
On August 3, 2025 10:48:08 a.m. EDT, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> wrote:
I'm going off on a tangent here, but imagine if we could mark a function (or lambda) as follows:
int Func(double) throw_on_nullptr
{
. . .
}
If you try to dereference a nullptr in this function, or if you perform addition or subtraction on a nullptr, it throws std::nullptr_t.
Maybe?
Received on 2025-08-05 17:24:08