Description
Will your feature suggestion eliminate X% of security vulnerabilities of a given kind in current C++ code?
I am not a security expert, but one thing comes to my mind is copying sensitive data like passwords/keys requires explicit removal/zeroing data on the caller site after it is passed to callee. How it might help? The callee usually knows that the data passed is sensitive and erase/zeroed it so if this is only one instance of such data then mission accomplished callee makes sure it is safe, but if it is not the only copy then the same safe memory utilization is needed on the whole path of these data from IO code to the callee.
Will your feature suggestion automate or eliminate X% of current C++ guidance literature?
I think so, there is plenty of guidance to use std::move when performance does matter, and this is c++ it is always a matter. Actually, this is my the most ever used part of std namespace.
I use c++ for 20+ years, and I still get caught by this code(written even by me) regularly
std::vector v = {...};
auto& x = v[0];
// I can't always predict from the function name that v doesn't reallocate due to inserting in the whole call tree
mutateVector(v); // v.push_back(0) somewhere deep in call tree.
x = 10; <- SOMETIMES x is invalid because vector doesn't preserve iterators on insert
today tools can't catch it, because there are significantly more cases when mutableVector() simply changes some items' values rather than rearranging them. If these tools warn there would be almost always false alarms.
std2
vector: type = {
push_back : (this, val: T) = ... - both this and val passed by move, passing this by move clearly indicates all iterators invalidated
operator [] : (inout this, index: size_t)->T& = ... - this signature clearly indicates NO iterators invalidated
};
v: std2::vector = { ... };
x :&auto = v[0];
v.push_back(0); <- warning x is a dangling pointer
if v is passed outside as an out parameter then push_back simply doesn't compile.
Describe alternatives you've considered.
I don't think I need. We all know it and this is the current default - copy semantic.
Basically, I want rust/val move semantic to be the default semantic in cpp2. This means instead of making function parameters in by default it should be move by default. This matches very well with the mutable local variables, all copies become explicit. Having default move semantic allows to separate inout (mutable operations) from move(ownership transfer operations). push_back/insert/remove are ownership operations where is operator [] is not - is is always memory safe to use its result until ownership transferred. No borrow checker needed(rust), no math guarantee needed(val) just making a warning is enough but this is not a false positive warning.
Yes, this adds some extra amount of "noise" compared to implicit in, but we have this a lot in c++ (const &) and it is ok.