GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++

Libstdc++: Fix recent std::flat_map test with COW std::string

The std::flat_map test is fixed to disable constant evaluation when std::string is not constexpr.

A recent test added for std::flat_map in libstdc++ used std::string in a context requiring constant evaluation. However, std::string is not always constexpr, particularly when using a copy-on-write (COW) implementation. This commit fixes the test by disabling constant evaluation when std::string is not constexpr, ensuring the test passes in all configurations.

In Details

The test_constexpr function in testsuite/23_containers/flat_map/1.cc now conditionally skips test10 if std::string is not constexpr. This avoids errors when libstdc++ is configured to use a COW std::string implementation. A toolchain developer might not immediately be aware of the interaction between std::flat_map's constexpr requirements and the different std::string implementations.

For Context

constexpr in C++ allows certain expressions to be evaluated at compile time, which can lead to performance improvements. This commit fixes a test for the std::flat_map container in the C++ standard library. The test was incorrectly trying to use std::string in a context where it needed to be evaluated at compile time, but std::string doesn't always support that. The fix makes the test skip the compile-time evaluation when std::string doesn't support it, ensuring the test passes correctly.

Filed Under: libstdc++testsuiteflat_mapconstexprstd::string