https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98465
--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> --- Comparing the code emitted by GCC 10 and the current trunk shows that the former doesn't inline std::string::replace() regardless of the inlining limit. The translation unit obtained with the former shows declarations of explicit instantiations of basic_string: $ g++-10 -O2 -E -Wall -g t.C | grep template | grep basic_string template<typename, typename, typename> friend class basic_stringbuf; extern template class basic_string<char>; extern template class basic_string<wchar_t>; Current trunk doesn't declare them which is what allows std::string::replace to be inlined. Removing the declaration of the explicit instantiation from the translation unit lets GCC 10 inline string::replace but the warning is not issued because the location of the call is in a system header. But enabling warning for those via -Wsystem-headers shows the warning even with GCC 10: $ g++-10 -E pr98465.C | sed "/extern template class basic_string/d" > pr98465.ii && g++-10 -O2 -S -Wall -Wsystem-headers pr98465.ii In file included from /build/gcc-10-branch/x86_64-pc-linux-gnu/libstdc++-v3/include/string:56, from pr98465.C:1: /build/gcc-10-branch/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc: In function ‘void f(std::string&)’: /build/gcc-10-branch/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:456:20: warning: offset ‘2’ outside bounds of constant string [-Warray-bounds] 456 | this->_S_copy(__p, __s + __len2 - __len1, __len2); | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pr98465.C:3:12: note: ‘constantString’ declared here 3 | const char constantString[] = {42, 53}; | ^~~~~~~~~~~~~~ In file included from /build/gcc-10-branch/x86_64-pc-linux-gnu/libstdc++-v3/include/string:40, from pr98465.C:1: In static member function ‘static std::char_traits<char>::char_type* std::char_traits<char>::copy(std::char_traits<char>::char_type*, const char_type*, std::size_t)’, inlined from ‘void f(std::string&)’ at /build/gcc-10-branch/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:351:21: /build/gcc-10-branch/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/char_traits.h:395:49: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ reading 2 bytes from a region of size 0 [-Wstringop-overflow=] 395 | return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n)); | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~