admin管理员组

文章数量:1315783

Take a look at this snippet:

// test.cpp
#include <print>
#include <vector>

int main () {
    std::vector<int> vec = {1,2,3};
    std::println("vector: {}",vec);

    return 0;
}

From here I understood that the C++23 feature "support for the formatted output library " (P2093R14) had been added in GCC 14, Clang 18 and MSVC 19.37.

Compiled with MSVC 19.42 the program yields the desired ouput:

cl /EHs test.cpp /std:c++latest

D:\>test.exe vector: [1, 2, 3]

But with GCC 14 and Clang 19 it does not compile.

clang++ test.cpp -std=c++23

/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/format:4065:3: error: 
static assertion failed due to requirement 
'is_default_constructible_v<std::formatter<std::vector<int, std::allocator<int>>, 
char>>': <plenty of more lines to follow>

g++ test.cpp -std=c++23

/usr/include/c++/14/format:4065:10: error: static assertion failed:
std::formatter must be specialized for each type being formatted
(is_default_constructible_v<formatter<_Args, _CharT>> && ...)

Am I missing something?

Take a look at this snippet:

// test.cpp
#include <print>
#include <vector>

int main () {
    std::vector<int> vec = {1,2,3};
    std::println("vector: {}",vec);

    return 0;
}

From here I understood that the C++23 feature "support for the formatted output library " (P2093R14) had been added in GCC 14, Clang 18 and MSVC 19.37.

Compiled with MSVC 19.42 the program yields the desired ouput:

cl /EHs test.cpp /std:c++latest

D:\>test.exe vector: [1, 2, 3]

But with GCC 14 and Clang 19 it does not compile.

clang++ test.cpp -std=c++23

/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/format:4065:3: error: 
static assertion failed due to requirement 
'is_default_constructible_v<std::formatter<std::vector<int, std::allocator<int>>, 
char>>': <plenty of more lines to follow>

g++ test.cpp -std=c++23

/usr/include/c++/14/format:4065:10: error: static assertion failed:
std::formatter must be specialized for each type being formatted
(is_default_constructible_v<formatter<_Args, _CharT>> && ...)

Am I missing something?

Share Improve this question asked Jan 30 at 13:34 Angle.BracketAngle.Bracket 1,5321 gold badge15 silver badges36 bronze badges 4
  • 2 The corresponding libstdc++ page shows that specific feature is only available from libstdc++ 14.1 onwards. Furthermore, it looks like your clang++ is also using libstdc++ instead of libc++.. – Botje Commented Jan 30 at 13:44
  • 3 <plenty of more lines to follow> - those lines are noisy but provide information. Please don't delete them. Use a quoted-code-block or something. – Yakk - Adam Nevraumont Commented Jan 30 at 15:03
  • 1 Not implemented yet see this table row: Formatting Ranges (FTM)* godbolt./z/Ezrj3EPs5 – Marek R Commented Jan 30 at 15:49
  • @Botje apt -qq list libstdc++-14-dev says libstdc++-14-dev/noble-updates,noble-security,now 14.2.0-4ubuntu2~24.04 amd64 [installed] – Angle.Bracket Commented Jan 30 at 15:57
Add a comment  | 

1 Answer 1

Reset to default 9

Formatter for std::vector is a part of P2286R8 "Formatting Ranges" and is not yet supported by libstdc++. (Both GCC and Clang use libstdc++ as the default standard library implementation on Linux.)

本文标签: cWhy does stdprintln with STL containers not compile with GCC and ClangStack Overflow