]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix constification in range_formatter::format [PR109162]
authorTomasz Kamiński <tkaminsk@redhat.com>
Wed, 16 Apr 2025 11:39:04 +0000 (13:39 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Wed, 16 Apr 2025 12:32:57 +0000 (14:32 +0200)
commitaef87975224b0a4b5b103f241fd366b0e3a21360
tree62e40c32b04285e548f944f40adf1f63f8ae2c2b
parentfa99720e9f3447565d274baaa81e23c2ddab4a67
libstdc++: Fix constification in range_formatter::format [PR109162]

The _Rg is deduced to lvalue reference for the lvalue arguments,
and in such case __format::__maybe_const_range<_Rg, _CharT> is always _Rg
(adding const to reference does not change behavior).

Now we correctly check if _Range = remove_reference_t<_Rg> is const
formattable range, furthermore as range_formatter<T> can only format
ranges of values of type (possibly const) _Tp, we additional check if the
remove_cvref_t<range_reference_t<const _Range>> is _Tp.

The range_reference_t<R> and range_reference_t<const R> have different
types (modulo remove_cvref_t) for std::vector<bool> (::reference and bool)
or flat_map<T, U> (pair<const T&, U&> and pair<const T&, const U&>).

PR libstdc++/109162

libstdc++-v3/ChangeLog:

* include/std/format (range_formatter::format): Format const range,
only if reference type is not changed.
* testsuite/std/format/ranges/formatter.cc: New tests.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
libstdc++-v3/include/std/format
libstdc++-v3/testsuite/std/format/ranges/formatter.cc