public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug libstdc++/112832] New: [std::format] Broken non-SFINAE-friendly `set_debug_format()` for `const char *` formatter @ 2023-12-03 16:53 iamsupermouse at mail dot ru 2023-12-04 11:36 ` [Bug libstdc++/112832] " redi at gcc dot gnu.org ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: iamsupermouse at mail dot ru @ 2023-12-03 16:53 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112832 Bug ID: 112832 Summary: [std::format] Broken non-SFINAE-friendly `set_debug_format()` for `const char *` formatter Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: iamsupermouse at mail dot ru Target Milestone: --- GCC doesn't seem to implement `{:?}` debug format for strings yet. Yet for some reason `std::formatter<const char *>` has a `set_debug_format()` function, which causes a hard error when used (isn't SFINAE-friendly). `set_debug_format()` should be SFINAE-friendly, to allow the user to call it conditionally when available. Here's a code sample that fails to compile because of it: https://gcc.godbolt.org/z/PbfnsxE9n (still fails in GCC 14 trunk) #include <format> #include <iostream> #include <string> #include <type_traits> #include <utility> template <typename T> struct PreferDebugFormat { T ⌖ constexpr PreferDebugFormat(T &target) : target(target) {} }; template <typename T> PreferDebugFormat(T &&) -> PreferDebugFormat<std::remove_reference_t<T> &>; template <typename T, typename CharT> struct std::formatter<PreferDebugFormat<T>, CharT> : std::formatter<std::remove_cvref_t<T>, CharT> { using base = std::formatter<std::remove_cvref_t<T>, CharT>; constexpr decltype(auto) parse(std::basic_format_parse_context<CharT> &parse_ctx) { if constexpr (requires{this->set_debug_format();}) this->set_debug_format(); return base::parse(parse_ctx); } template <typename OutputIt> constexpr decltype(auto) format(const PreferDebugFormat<T> &arg, std::basic_format_context<OutputIt, CharT> &format_ctx) const { return base::format(arg.target, format_ctx); } }; template <typename T> std::string ToDebugString(const T &value) { return std::format("{}", PreferDebugFormat(value)); } int main() { std::cout << ToDebugString("foo\nbar") << '\n'; // hard error == BUG std::cout << ToDebugString(std::string_view("foo\nbar")) << '\n'; // ok, no debug format yet std::cout << ToDebugString(42) << '\n'; // ok, no debug format } ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/112832] [std::format] Broken non-SFINAE-friendly `set_debug_format()` for `const char *` formatter 2023-12-03 16:53 [Bug libstdc++/112832] New: [std::format] Broken non-SFINAE-friendly `set_debug_format()` for `const char *` formatter iamsupermouse at mail dot ru @ 2023-12-04 11:36 ` redi at gcc dot gnu.org 2023-12-05 16:49 ` cvs-commit at gcc dot gnu.org ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: redi at gcc dot gnu.org @ 2023-12-04 11:36 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112832 Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2023-12-04 Ever confirmed|0 |1 Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org Status|UNCONFIRMED |ASSIGNED Target Milestone|--- |13.3 --- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Egor from comment #0) > GCC doesn't seem to implement `{:?}` debug format for strings yet. Correct, see PR 109162 > Yet for some reason `std::formatter<const char *>` has a > `set_debug_format()` function, which causes a hard error when used (isn't > SFINAE-friendly). The error has nothing to do with it being SFINAE-friendly or not. > `set_debug_format()` should be SFINAE-friendly, to allow the user to call it > conditionally when available. No, it should just not exist yet. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/112832] [std::format] Broken non-SFINAE-friendly `set_debug_format()` for `const char *` formatter 2023-12-03 16:53 [Bug libstdc++/112832] New: [std::format] Broken non-SFINAE-friendly `set_debug_format()` for `const char *` formatter iamsupermouse at mail dot ru 2023-12-04 11:36 ` [Bug libstdc++/112832] " redi at gcc dot gnu.org @ 2023-12-05 16:49 ` cvs-commit at gcc dot gnu.org 2023-12-06 14:44 ` cvs-commit at gcc dot gnu.org 2023-12-06 14:45 ` redi at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: cvs-commit at gcc dot gnu.org @ 2023-12-05 16:49 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112832 --- Comment #2 from GCC 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:3cd73543a1122d3c81409e3e9a26c3e94c3d324f commit r14-6189-g3cd73543a1122d3c81409e3e9a26c3e94c3d324f Author: Jonathan Wakely <jwakely@redhat.com> Date: Mon Dec 4 12:03:28 2023 +0000 libstdc++: Disable std::formatter::set_debug_format [PR112832] All set_debug_format member functions should be guarded by the __cpp_lib_formatting_ranges macro (which is not defined yet). libstdc++-v3/ChangeLog: PR libstdc++/112832 * include/std/format (formatter::set_debug_format): Ensure this member is defined conditionally for all specializations. * testsuite/std/format/formatter/112832.cc: New test. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/112832] [std::format] Broken non-SFINAE-friendly `set_debug_format()` for `const char *` formatter 2023-12-03 16:53 [Bug libstdc++/112832] New: [std::format] Broken non-SFINAE-friendly `set_debug_format()` for `const char *` formatter iamsupermouse at mail dot ru 2023-12-04 11:36 ` [Bug libstdc++/112832] " redi at gcc dot gnu.org 2023-12-05 16:49 ` cvs-commit at gcc dot gnu.org @ 2023-12-06 14:44 ` cvs-commit at gcc dot gnu.org 2023-12-06 14:45 ` redi at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: cvs-commit at gcc dot gnu.org @ 2023-12-06 14:44 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112832 --- Comment #3 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:d40796e3813fdf646ca7b7ce9630d5cc121353b4 commit r13-8130-gd40796e3813fdf646ca7b7ce9630d5cc121353b4 Author: Jonathan Wakely <jwakely@redhat.com> Date: Mon Dec 4 12:03:28 2023 +0000 libstdc++: Disable std::formatter::set_debug_format [PR112832] All set_debug_format member functions should be guarded by the __cpp_lib_formatting_ranges macro (which is not defined yet). libstdc++-v3/ChangeLog: PR libstdc++/112832 * include/std/format (formatter::set_debug_format): Ensure this member is defined conditionally for all specializations. * testsuite/std/format/formatter/112832.cc: New test. (cherry picked from commit 3cd73543a1122d3c81409e3e9a26c3e94c3d324f) ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/112832] [std::format] Broken non-SFINAE-friendly `set_debug_format()` for `const char *` formatter 2023-12-03 16:53 [Bug libstdc++/112832] New: [std::format] Broken non-SFINAE-friendly `set_debug_format()` for `const char *` formatter iamsupermouse at mail dot ru ` (2 preceding siblings ...) 2023-12-06 14:44 ` cvs-commit at gcc dot gnu.org @ 2023-12-06 14:45 ` redi at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: redi at gcc dot gnu.org @ 2023-12-06 14:45 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112832 Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |RESOLVED Resolution|--- |FIXED --- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> --- Fixed for 13.3, thanks for the report. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-12-06 14:45 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-12-03 16:53 [Bug libstdc++/112832] New: [std::format] Broken non-SFINAE-friendly `set_debug_format()` for `const char *` formatter iamsupermouse at mail dot ru 2023-12-04 11:36 ` [Bug libstdc++/112832] " redi at gcc dot gnu.org 2023-12-05 16:49 ` cvs-commit at gcc dot gnu.org 2023-12-06 14:44 ` cvs-commit at gcc dot gnu.org 2023-12-06 14:45 ` 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).