int foo(const int &x) {
int &y { const_cast<int &>(x) };
y += 1;
return y;
}
It may invoke undefined behavior if the original int was declared const, but this still compiles with no warnings on GCC with -Wall -Wextra.
It may be really bad style, but not mutating const references is not enforced by the compiler. Hence you aren't guaranteed that your const references actually stay unmodified if you pass them to a function.
It may be really bad style, but not mutating const references is not enforced by the compiler. Hence you aren't guaranteed that your const references actually stay unmodified if you pass them to a function.