public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/112607] New: <format>: _Normalize does not consider char_type for the basic_string_view case
@ 2023-11-18 16:28 hewillk at gmail dot com
2023-11-18 18:09 ` [Bug libstdc++/112607] " redi at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: hewillk at gmail dot com @ 2023-11-18 16:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112607
Bug ID: 112607
Summary: <format>: _Normalize does not consider char_type for
the basic_string_view case
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
When T in basic_format_arg(T& v) is a specialization of basic_string_view or
basic_string, format#arg-6.8 indicates:
otherwise, if TD is a specialization of basic_string_view or basic_string and
TD::value_type is char_type, initializes value with
basic_string_view<char_type>(v.data(), v.size());
We need to consider TD::value_type is char_type.
However, libstd++ only uses __is_specialization_of to detect whether T is a
specialization of basic_string_view or basic_string (format#L3118-L3121):
else if constexpr (__is_specialization_of<_Td, basic_string_view>)
return type_identity<basic_string_view<_CharT>>();
else if constexpr (__is_specialization_of<_Td, basic_string>)
return type_identity<basic_string_view<_CharT>>();
This causes basic_format_arg to incorrectly use wstring_view to initialize
string_view when customizing std::wstring.
https://godbolt.org/z/6Kd16z8qK
#include <format>
template<>
struct std::formatter<std::wstring> : std::formatter<std::string> {
auto format(const std::wstring& obj, auto& ctx) const {
return std::formatter<std::string>::format(" ", ctx);
}
};
int main(){
std::wstring wstr;
std::string str = std::format("{}", wstr);
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/112607] <format>: _Normalize does not consider char_type for the basic_string_view case
2023-11-18 16:28 [Bug libstdc++/112607] New: <format>: _Normalize does not consider char_type for the basic_string_view case hewillk at gmail dot com
@ 2023-11-18 18:09 ` redi at gcc dot gnu.org
2023-11-18 18:15 ` redi at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-11-18 18:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112607
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
That is not a valid specialization since it doesn't depend on a program-defined
type.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/112607] <format>: _Normalize does not consider char_type for the basic_string_view case
2023-11-18 16:28 [Bug libstdc++/112607] New: <format>: _Normalize does not consider char_type for the basic_string_view case hewillk at gmail dot com
2023-11-18 18:09 ` [Bug libstdc++/112607] " redi at gcc dot gnu.org
@ 2023-11-18 18:15 ` redi at gcc dot gnu.org
2023-11-18 18:20 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-11-18 18:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112607
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
basic_string<wchar_t, mytraits> would be a valid program-defined specialization
though.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/112607] <format>: _Normalize does not consider char_type for the basic_string_view case
2023-11-18 16:28 [Bug libstdc++/112607] New: <format>: _Normalize does not consider char_type for the basic_string_view case hewillk at gmail dot com
2023-11-18 18:09 ` [Bug libstdc++/112607] " redi at gcc dot gnu.org
2023-11-18 18:15 ` redi at gcc dot gnu.org
@ 2023-11-18 18:20 ` redi at gcc dot gnu.org
2023-11-18 19:42 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-11-18 18:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112607
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The standard tries quite hard to avoid this kind of specialization:
https://eel.is/c++draft/format.formatter.spec#note-1
But I suppose you can contrive this kind of custom formatter, or the inverse,
i.e. std::formatter<std::basic_string<char, mytraits>, wchar_t>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/112607] <format>: _Normalize does not consider char_type for the basic_string_view case
2023-11-18 16:28 [Bug libstdc++/112607] New: <format>: _Normalize does not consider char_type for the basic_string_view case hewillk at gmail dot com
` (2 preceding siblings ...)
2023-11-18 18:20 ` redi at gcc dot gnu.org
@ 2023-11-18 19:42 ` redi at gcc dot gnu.org
2023-11-18 21:44 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-11-18 19:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112607
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
Ever confirmed|0 |1
Last reconfirmed| |2023-11-18
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/112607] <format>: _Normalize does not consider char_type for the basic_string_view case
2023-11-18 16:28 [Bug libstdc++/112607] New: <format>: _Normalize does not consider char_type for the basic_string_view case hewillk at gmail dot com
` (3 preceding siblings ...)
2023-11-18 19:42 ` redi at gcc dot gnu.org
@ 2023-11-18 21:44 ` cvs-commit at gcc dot gnu.org
2023-11-18 21:52 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-18 21:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112607
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:279e407a06cc676d8e6e0bb5755b0a804e05377c
commit r14-5588-g279e407a06cc676d8e6e0bb5755b0a804e05377c
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Sat Nov 18 20:56:35 2023 +0000
libstdc++: Check string value_type in std::make_format_args [PR112607]
libstdc++-v3/ChangeLog:
PR libstdc++/112607
* include/std/format (basic_format_arg::_S_to_arg_type): Check
value_type for basic_string_view and basic_string
specializations.
* testsuite/std/format/arguments/112607.cc: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/112607] <format>: _Normalize does not consider char_type for the basic_string_view case
2023-11-18 16:28 [Bug libstdc++/112607] New: <format>: _Normalize does not consider char_type for the basic_string_view case hewillk at gmail dot com
` (4 preceding siblings ...)
2023-11-18 21:44 ` cvs-commit at gcc dot gnu.org
@ 2023-11-18 21:52 ` redi at gcc dot gnu.org
2023-11-28 22:30 ` cvs-commit at gcc dot gnu.org
2023-11-28 22:32 ` redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-11-18 21:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112607
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |13.3
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk so far.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/112607] <format>: _Normalize does not consider char_type for the basic_string_view case
2023-11-18 16:28 [Bug libstdc++/112607] New: <format>: _Normalize does not consider char_type for the basic_string_view case hewillk at gmail dot com
` (5 preceding siblings ...)
2023-11-18 21:52 ` redi at gcc dot gnu.org
@ 2023-11-28 22:30 ` cvs-commit at gcc dot gnu.org
2023-11-28 22:32 ` redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-28 22:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112607
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:
https://gcc.gnu.org/g:c7c92d61d32f6fd7746e2844f68d1936e2b6f6f6
commit r13-8105-gc7c92d61d32f6fd7746e2844f68d1936e2b6f6f6
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Sat Nov 18 20:56:35 2023 +0000
libstdc++: Check string value_type in std::make_format_args [PR112607]
libstdc++-v3/ChangeLog:
PR libstdc++/112607
* include/std/format (basic_format_arg::_S_to_arg_type): Check
value_type for basic_string_view and basic_string
specializations.
* testsuite/std/format/arguments/112607.cc: New test.
(cherry picked from commit 279e407a06cc676d8e6e0bb5755b0a804e05377c)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/112607] <format>: _Normalize does not consider char_type for the basic_string_view case
2023-11-18 16:28 [Bug libstdc++/112607] New: <format>: _Normalize does not consider char_type for the basic_string_view case hewillk at gmail dot com
` (6 preceding siblings ...)
2023-11-28 22:30 ` cvs-commit at gcc dot gnu.org
@ 2023-11-28 22:32 ` redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-11-28 22:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112607
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 13.3 as well, thanks for the report.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-11-28 22:32 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-18 16:28 [Bug libstdc++/112607] New: <format>: _Normalize does not consider char_type for the basic_string_view case hewillk at gmail dot com
2023-11-18 18:09 ` [Bug libstdc++/112607] " redi at gcc dot gnu.org
2023-11-18 18:15 ` redi at gcc dot gnu.org
2023-11-18 18:20 ` redi at gcc dot gnu.org
2023-11-18 19:42 ` redi at gcc dot gnu.org
2023-11-18 21:44 ` cvs-commit at gcc dot gnu.org
2023-11-18 21:52 ` redi at gcc dot gnu.org
2023-11-28 22:30 ` cvs-commit at gcc dot gnu.org
2023-11-28 22:32 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).