From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2B86C385C6F8; Sun, 3 Dec 2023 16:53:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B86C385C6F8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701622393; bh=X33rDe9py1qdI7ZIa/pmF/Xi3KolVe2WxV5H+mfYnME=; h=From:To:Subject:Date:From; b=wxOXwhWcRBY+EX0W3XQkIFD9fey+qxhbN3Z2ybOtRBELz7em367iIY/Ncrhfes2Xr RZ1INj1F737GQY2isPzUSuHERgdwyNhS57zJ22Sr3+4aKnJf67Cn7YPMGAc/dEzeGH gCoyGakLLLvD6FjUGHoDn/8vJ5Ab0p5eawZtTk+M= From: "iamsupermouse at mail dot ru" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/112832] New: [std::format] Broken non-SFINAE-friendly `set_debug_format()` for `const char *` formatter Date: Sun, 03 Dec 2023 16:53:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: iamsupermouse at mail dot ru X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112832 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` 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 #include #include #include #include template struct PreferDebugFormat { T ⌖ constexpr PreferDebugFormat(T &target) : target(target) {} }; template PreferDebugFormat(T &&) -> PreferDebugFormat= &>; template struct std::formatter, CharT> : std::formatter, CharT> { using base =3D std::formatter, CharT>; constexpr decltype(auto) parse(std::basic_format_parse_context &parse_ctx) { if constexpr (requires{this->set_debug_format();}) this->set_debug_format(); return base::parse(parse_ctx); } template constexpr decltype(auto) format(const PreferDebugFormat &arg, std::basic_format_context &format_ctx) const { return base::format(arg.target, format_ctx); } }; template std::string ToDebugString(const T &value) { return std::format("{}", PreferDebugFormat(value)); } int main() { std::cout << ToDebugString("foo\nbar") << '\n'; // hard error =3D= =3D BUG std::cout << ToDebugString(std::string_view("foo\nbar")) << '\n'; // ok, no debug format yet std::cout << ToDebugString(42) << '\n'; // ok, no debug format }=