C++ Logo

std-proposals

Advanced search

[std-proposals] Forget forget let's redact

From: Henry Skoglund <henry_at_[hidden]>
Date: Mon, 17 Aug 2026 02:12:31 +0200
Hi, I reread all replies to my previous "forget" post, I think I'm
smarter now :-)
Here's my new take: let's introduce a std::redact() primarily for safety
reasons:
void f()
{
     int a = 42;
     int b = 41;
     b = std::move(a);
     std::redact(a);
     int c = a; // <--- error: a is redacted, cannot be used
}

Or for code maintenance/documentation purposes:
void f(int raw)
{
     int cooked = raw * 4711;
     std::redact(raw);
...
// lots of code
...
     int furtherproc = raw; // <--- error: raw is redacted, cannot be used
}
The idea is: we're done with raw, please use cooked for new code.


You can only redact a variable within the same scope:
void f()
{
     int a = 42;
     int b = 41;
     {
         b = std::move(a);
         std::redact(a); // <--- error: no "a" found to redact
     }
}

also you need to stay in the same control path:
void f()
{
     int a = 42;
     int b = 41;
     goto label;
     b = std::move(a);
     std::redact(a); // <--- error: not all control paths lead to a redact
label:;
}

IOW: a std::redact() is valid whenever a redeclaration of the same
redactee gives a "redefinition..." or "shadows a function argument"
error. If a redeclaration results in a good shadowing, then
std::redact() should fail.

If code with std::redact() compiles ok, then removing the std::redact()
and compiling again should return the same binary, i.e. no runtime
differences.

Bonus point: no such feature exists in Rust.

Future idea: allow std::redact(variable, "reason");
e.g. std::redact(a,"move"); or std::redact(raw,"don't use");

Rgrds Henry

Received on 2026-08-17 00:12:41