g++ 12 -std=gnu++20

Dimitry Andric dimitry@unified-streaming.com
Thu Oct 31 15:34:57 GMT 2024


On 31 Oct 2024, at 06:40, Brian Inglis via Cygwin <cygwin@cygwin.com> wrote:
> 
> On 2024-10-30 10:30, Dimitry Andric via Cygwin wrote:
>> On 30 Oct 2024, at 17:14, Csaba Ráduly via Cygwin wrote:
>>> On 30/10/2024 17:00, Dimitry Andric via Cygwin wrote:
>>>> #include<string>
>>>> #include<cassert>
>>>> 
>>>> constexpr bool foo()
>>>> {
>>>>   std::string str2{"abcwe"};
>>>>   return str2.size()==5;
>>>> }
>>>> 
>>>> static_assert(foo());
>>>> 
>>>> int main()
>>>> {
>>>>   assert(foo());
>>>> }
>>> 
>>> Seems like _GLIBCXX_USE_CXX11_ABI is not defined by default.
>> Indeed, /usr/lib/gcc/x86_64-pc-cygwin/12/include/c++/x86_64-pc-cygwin/bits/c++config.h shows:
>>    317  # define _GLIBCXX_USE_DUAL_ABI 1
>>    318
>>    319  #if ! _GLIBCXX_USE_DUAL_ABI
>>    320  // Ignore any pre-defined value of _GLIBCXX_USE_CXX11_ABI
>>    321  # undef _GLIBCXX_USE_CXX11_ABI
>>    322  #endif
>>    323
>>    324  #ifndef _GLIBCXX_USE_CXX11_ABI
>>    325  # define _GLIBCXX_USE_CXX11_ABI 0
>>    326  #endif
>>  Also, g++ -v shows --with-default-libstdcxx-abi=gcc4-compatible, so I guess this was deliberate on the part of the packagers. Probably for backwards compatibility reasons?
> 
> Okay, sorry, I typoed an extra _ before _GLIBCXX_NOEXCEPT!
> 
> Cygwin gcc/g++ 13.3 is available as a test package; only with .4/.5 are gcc version features and fixes considered stable.
> 
> The build is requesting -std=gnu++20, so why is 11 ABI relevant?
> 
> As I want to use the latest language, why is gcc 4 compatible ABI *default* relevant?
> 
> What can I do in the package build to get g++ to not use the default but whatever is required to support the latest language?
> 
> Where can I find docs on these symbols and their meanings, uses, and settings?

It is a historical artifact that has been dragged along for years. See https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html for more information.

During the gcc 5.1 release, changes were made to libstdc++ that made the ABI incompatible with previous releases, specifically for std::string. You can define _GLIBCXX_USE_CXX11_ABI to 1 to use the 'new' ABI, but then it becomes tricky to link your code to libraries compiled with older versions of libstdc++, or newer versions that define _GLIBCXX_USE_CXX11_ABI to 0.

I think most Linux distributions have switched fully to the new ABI by now, and dropped support for the old ABI, so they configure their gcc's with _GLIBCXX_USE_CXX11_ABI=1 by default.

-Dimitry



More information about the Cygwin mailing list