https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105545
--- Comment #6 from Tom Hughes ---
The reason it only happens with -D_GLIBCXX_ASSERTIONS or in C++20 mode is that
both of those stop the use of the explicit instantiations for basic_string and
cause them to be implicitly instantiated.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105545
--- Comment #5 from Tom Hughes ---
On top of -O1 you seem to need all of -fexpensive-optimizations -ftree-vrp
-fipa-sra to trigger it.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105545
--- Comment #4 from Tom Hughes ---
You don't need -D_GLIBCXX_ASSERTIONS in C++20 mode but you do in C++17 mode it
seems.