Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does GCC support C++20 std::format?

Tags:

c++

gcc

stl

c++20

If it doesn't, do you know what compiler or version will?

See cppreference/format.

like image 613
PorssiMies Avatar asked Sep 03 '20 12:09

PorssiMies


People also ask

Is C++20 supported on GCC?

C++20 Support in GCC GCC has experimental support for the latest revision of the C++ standard, which was published in 2020. C++20 features are available since GCC 8.

Which version of C++ does GCC support?

GCC supports the original ISO C++ standard published in 1998, and the 2011, 2014, 2017 and mostly 2020 revisions. The original ISO C++ standard was published as the ISO standard (ISO/IEC 14882:1998) and amended by a Technical Corrigenda published in 2003 (ISO/IEC 14882:2003).

Does clang support C++20 format?

Clang doesn't use C++20 by default, so you must specify it explicitly. Clang uses libstdc++ standard library on Linux by default (for compatibility with shared libraries), so in such case you won't be using the Clang's standard library by default, and libstdc++ hasn't implemented text formatting yet.

Is C++20 fully supported?

Visual Studio 2019 (latest version 16.10, on Windows) is the only IDE currently coming with a compiler that fully supports C++20.


Video Answer


3 Answers

Does gcc support C++20 std::format?

Not yet!

There's no compiler support yet, not even gcc 11. See Text formatting in Library features.

Compiler support for C++20 library features

like image 117
John Park Avatar answered Oct 19 '22 09:10

John Park


As of September 2022, NO, GCC 12 doesn't support std::format yet.

MSVC (version 16.10 and above) is the only compiler that fully supports std::format. Clang 14 (with libc++14) also has almost full support for std::format.

Since std::format is based on fmt library, you can use fmt::format until std::format arrives in GCC.

{fmt} library GitHub repo


See Compiler support here :-

  • gcc (libstdc++)
  • clang (libc++)
  • msvc (vc++)
like image 28
Tanishq-Banyal Avatar answered Oct 19 '22 08:10

Tanishq-Banyal


As of today (5 September 2022), GCC 12.2 does not support this feature. Or rather, its standard library implementation doesn't support it (cause it's a library feature, not the compiler-one).

You can try Clang 14.0.0 and upward for now, but note following:

libc++ of Clang 14.0.0 has std::format support but: "The paper is implemented but still marked as an incomplete feature. Not yet implemented LWG-issues will cause API and ABI breakage" as mentioned here

Also you can try MSVC 16.10 and upward. Support of std::format is mentioned as complete.


Standard library current status can be seen here:

  • GCC: libstdc++

  • Clang: libc++

  • MSVC: msvcp

like image 18
IGR94 Avatar answered Oct 19 '22 08:10

IGR94