https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103827
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> --- That would be undefined, because s is defined const and so doing const_cast and then modifying it is undefined behaviour. However, this would be fine: #include <string> int foo (const std::string s); int foo (std::string s) { s = "I am long string over 15 chars"; return s.size(); } The const in the first declaration of foo is meaningless, it doesn't mean it is necessarily const in the function definition.