https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109162
--- Comment #13 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Tomasz Kaminski <tkami...@gcc.gnu.org>: https://gcc.gnu.org/g:aef87975224b0a4b5b103f241fd366b0e3a21360 commit r15-9520-gaef87975224b0a4b5b103f241fd366b0e3a21360 Author: Tomasz KamiÅski <tkami...@redhat.com> Date: Wed Apr 16 13:39:04 2025 +0200 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 <jwak...@redhat.com> Signed-off-by: Tomasz KamiÅski <tkami...@redhat.com>