I think some systems have a "secure memset" function that can be used for things like this - i.e. one that's guaranteed not to be optimized out.
The compiler can, and will, make copies of data behind the scenes. And not erase said copies.
What we really need is a keyword / modifier that says that when X passes out of scope no state related to X may be leaked. Ideally, that can be applied to a function / block as well as a variable.
(Or rather, not necessarily no state. Read "as little state as possible", preferably with modifiers that panic unless the compiler can ensure specific things.)
On the other hand, something as simple as a keyword marking a variable as "as secure as possible given hardware constraints (read: should wipe any temporary copies and the variable itself after it goes out of scope, should attempt to prevent it from being written to non-volatile storage, that sort of thing)" (sort of like how inline works), with compilers required to bail if the constraint cannot be done to the level specified, would be a massive step in the right direction.
There is, quite literally, no way to ensure data is not leaked (namely, that data is zeroed / etc) in portable C / C++.
With C it's far too easy to get the data back.
Also, you missed the worst example: CPU cache.