Date: Sun, 16 Aug 2026 17:39:10 +0200
On 2026-08-13 23:57, Jonathan Grant wrote:
>
> On 09/08/2026 17:29, Henry Skoglund via Std-Proposals wrote:
>> Hi, for a long time now in C++ we have the const keyword, which disallows writing over a variable.
>>
>> What if we also want to disallow *reading* a variable?
> Henry
>
> Would my compile-time Forget meet your needs? it works at compile-time
> It does this using P4021 compile_assert
>
> βint main()β at main.cpp:17:25:
> forget.hpp:26:9: error: call to β_compile_assert_fail_0β declared with attribute error: Forget: cannot access a forgotten value
>
>
> https://github.com/jonnygrant/compile_assert/tree/main/experiments/forget
>
> It's just an example to show how to prevent access, not production code.
> Which compiler are you using?
>
> Kind regards
> Jonathan
>
Hi Jonathan, I tried your compile-time Forget on GCC 13.3.0 and it works
fine. But it's tricky with scopes, for example:
...
Forget<int> a(42);
if (rand() % 2)
{
// remove access to 'a'
Forget<int> b(a);
int try_to_access = a;
}
int try_to_access2 = a;
...
Ideally I should get an error message like 'Not all control paths lead
to a Forget' or if we allow only Forgets in the same scope, an error
like 'A Forget has to be in the same scope as the Forgetee'.
>
> On 09/08/2026 17:29, Henry Skoglund via Std-Proposals wrote:
>> Hi, for a long time now in C++ we have the const keyword, which disallows writing over a variable.
>>
>> What if we also want to disallow *reading* a variable?
> Henry
>
> Would my compile-time Forget meet your needs? it works at compile-time
> It does this using P4021 compile_assert
>
> βint main()β at main.cpp:17:25:
> forget.hpp:26:9: error: call to β_compile_assert_fail_0β declared with attribute error: Forget: cannot access a forgotten value
>
>
> https://github.com/jonnygrant/compile_assert/tree/main/experiments/forget
>
> It's just an example to show how to prevent access, not production code.
> Which compiler are you using?
>
> Kind regards
> Jonathan
>
Hi Jonathan, I tried your compile-time Forget on GCC 13.3.0 and it works
fine. But it's tricky with scopes, for example:
...
Forget<int> a(42);
if (rand() % 2)
{
// remove access to 'a'
Forget<int> b(a);
int try_to_access = a;
}
int try_to_access2 = a;
...
Ideally I should get an error message like 'Not all control paths lead
to a Forget' or if we allow only Forgets in the same scope, an error
like 'A Forget has to be in the same scope as the Forgetee'.
Received on 2026-08-16 15:39:16
