https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88512
--- Comment #12 from Jonny Grant <jg at jguk dot org> --- (In reply to Jonathan Wakely from comment #9) > It's easy for you to say that after looking at the reason it failed and > knowing what the code is trying to do (obviously "insert" modifies the > string, so it can't be const). But the compiler has to try every overload, > and doesn't know what your intention is, or what the word "insert" means. > > The problem here is (as before) that std::string has eight overloads of > insert (and just as many for assign, and begin, and replace etc), and > there's nothing the compiler can do about that. > > Potentially the compiler could be changed so that if all the overload > candidates are non-const and the object is const, it just says that. But > that's another fairly specialized diagnostic just for this case. Most > classes simply don't have eight overloads of the same function. Sounds good, those insert methods aren't 'const' so at least the first line could say that... eg: $ g++ -Wall -c -o int int.cpp int.cpp: In function ‘int main()’: int.cpp:13:21: error: no matching function for call to ‘std::string::insert(size_t, const string&) const’ str.insert(4, str2); ^ Note, ‘str’ is const and all ‘std::string::insert()’ methods are non-const