[Bug libstdc++/125359] [16/17 regression] undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)' on mingw since r16-8510

dragon-archer at outlook dot com via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125359

Zhongteng Gui <dragon-archer at outlook dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dragon-archer at outlook dot com

--- Comment #8 from Zhongteng Gui <dragon-archer at outlook dot com> ---
This issue is reported again at
https://github.com/msys2/MINGW-packages/issues/31015, and I did a few
investigation.

The problem only happens on a very specific situation:
1. `-std=c++20`, all other standards (C++11, 14, 17, 23, 26) doesn't have this
issue. Sadly C++20 is the default now.
2. `-fdeclone-ctor-dtor`, which is implied in `-Os` and `-Oz`. If you manually
disable this and compiles with `-Os -fno-declone-ctor-dtor` then it doesn't
cause the issue.

I suspect this comes from:
```
# if __cplusplus <= 202002L && _GLIBCXX_EXTERN_TEMPLATE > 0
  extern template class basic_string<char>;
```
at bits/basic_string.tcc#L1041, if I change `__cplusplus <= 202002L` to
`__cplusplus <= 201703L` then the problem also disappear (for all standards).
However I'm not sure whether that will cause other issues.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.