{"id":2224449,"url":"http://patchwork.ozlabs.org/api/patches/2224449/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/20260417124727.324242-1-jwakely@redhat.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260417124727.324242-1-jwakely@redhat.com>","list_archive_url":null,"date":"2026-04-17T12:47:16","name":"[committed] libstdc++: Add comments to non-obvious parts of std::print internals","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"77d486eaf1760fc3db5c20b24f040bc9c839149e","submitter":{"id":48004,"url":"http://patchwork.ozlabs.org/api/people/48004/?format=json","name":"Jonathan Wakely","email":"jwakely@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/20260417124727.324242-1-jwakely@redhat.com/mbox/","series":[{"id":500327,"url":"http://patchwork.ozlabs.org/api/series/500327/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=500327","date":"2026-04-17T12:47:16","name":"[committed] libstdc++: Add comments to non-obvious parts of std::print internals","version":1,"mbox":"http://patchwork.ozlabs.org/series/500327/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2224449/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2224449/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=SuD2FILs;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=SuD2FILs","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fxvn167gQz1yDF\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 22:48:05 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 6BC514C515FA\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 12:48:03 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id B090D4CCCA11\n for <gcc-patches@gcc.gnu.org>; Fri, 17 Apr 2026 12:47:32 +0000 (GMT)","from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-209-ONzNi6M_PUWWGdH42ystYQ-1; Fri,\n 17 Apr 2026 08:47:31 -0400","from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 3CECA1800605; Fri, 17 Apr 2026 12:47:30 +0000 (UTC)","from zen.kayari.org (unknown [10.44.48.52])\n by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id 2628D180047F; Fri, 17 Apr 2026 12:47:28 +0000 (UTC)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 6BC514C515FA","OpenDKIM Filter v2.11.0 sourceware.org B090D4CCCA11"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org B090D4CCCA11","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org B090D4CCCA11","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776430052; cv=none;\n b=FiDQCJBb22XNm9G2wGdWFTyrkl1R76666cW/iXVa9J2hOYEn5hazzmIVtpgjIcuzX7YCXzrNH3xxfhTKGWYEzmjynm9EtYzjx3KYg2a2tisgnSNNhSlgB2RbguD3kYSqSgVrUtUYRHKNewZXZB1NJvIs6hYeL4Ky+HdZFMeBPrw=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776430052; c=relaxed/simple;\n bh=4ckLBLBjFH4rNsJbkCT3WWmP4LyyFFrgnThfVkxBLE4=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=mNINzGxjjDsodBXYL1CYeQB5yRiik3gqfO3dD+lVaLGpJzwWx5sByKL7qOLielyzl993SqC/nPnpMUYKALgJ58g1Hrf32Hh9eW1tP0KdKSpK9pB5ZzNb/8yoaNPspwOxbDW9o4LXgQ41D1pMUbeEDpF7vDagl0gyUiz4xThBOV4=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776430052;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding;\n bh=/8YY/4gnd9lrGqe0RIRkgBK2an2W3k2E36xnasMVacw=;\n b=SuD2FILsADolrV6EbyLpH5JnwH063+Epy3vyHjgfAEOMW3Mlf2fS+ksZdMK+mpaYmfBM2R\n nb1mugkX8DMzgkfL8EXzjC8CxH+5Y8M7utQ2SVKZXI93/coOV6MC5uFi3uttnrb0xxFICZ\n AnD9xSpU+1rSYQgPIJWbkOaLVwTIYG4=","X-MC-Unique":"ONzNi6M_PUWWGdH42ystYQ-1","X-Mimecast-MFC-AGG-ID":"ONzNi6M_PUWWGdH42ystYQ_1776430050","From":"Jonathan Wakely <jwakely@redhat.com>","To":"libstdc++@gcc.gnu.org,\n\tgcc-patches@gcc.gnu.org","Subject":"[committed] libstdc++: Add comments to non-obvious parts of\n std::print internals","Date":"Fri, 17 Apr 2026 13:47:16 +0100","Message-ID":"<20260417124727.324242-1-jwakely@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.93","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"OXVJfYMfRsWR3NVQ7gPjNYDbtrupGBOv7X6rCgIa2Zw_1776430050","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","Content-Transfer-Encoding":"8bit","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"libstdc++-v3/ChangeLog:\n\n\t* include/bits/print.h (_File_sink): Add comments.\n---\n\nTested x86_64-linux, aarch64-linux, sparc-solaris.\n\nPushed to trunk.\n\n libstdc++-v3/include/bits/print.h | 36 ++++++++++++++++++++-----------\n 1 file changed, 23 insertions(+), 13 deletions(-)","diff":"diff --git a/libstdc++-v3/include/bits/print.h b/libstdc++-v3/include/bits/print.h\nindex 67a5a1729135..ab3ff9996126 100644\n--- a/libstdc++-v3/include/bits/print.h\n+++ b/libstdc++-v3/include/bits/print.h\n@@ -58,7 +58,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \n namespace __format\n {\n-#if _GLIBCXX_USE_STDIO_LOCKING && _GLIBCXX_USE_GLIBC_STDIO_EXT\n+#if _GLIBCXX_USE_STDIO_LOCKING && _GLIBCXX_USE_GLBC_STDIO_EXT\n   // These are defined in <stdio_ext.h> but we don't want to include that.\n   extern \"C\" int __fwritable(FILE*) noexcept;\n   extern \"C\" int __flbf(FILE*) noexcept;\n@@ -111,6 +111,8 @@ namespace __format\n       }\n \n       // Update the current position in the output buffer.\n+      // __n is the number of characters written to the _M_write_buf() span,\n+      // so will not exceed the size of the output buffer.\n       void\n       _M_bump(size_t __n) noexcept\n       { _M_file->_IO_write_ptr += __n; }\n@@ -160,12 +162,15 @@ namespace __format\n \tthis->_M_reset(_M_file._M_write_buf());\n     }\n \n+    // This calls I/O functions which are cancellation points, so they\n+    // could exit with a __forced_unwind exception. The noexcept(false)\n+    // allows that to propagate instead of terminating the process.\n     ~_File_sink() noexcept(false)\n     {\n       auto __s = this->_M_used();\n       if (__s.data() == this->_M_buf) // Unbuffered stream\n \t{\n-\t  _File_sink::_M_overflow();\n+\t  _File_sink::_M_overflow(); // Transfer _M_buf to stream.\n \t  if (_M_add_newline)\n \t    ::putc_unlocked('\\n', _M_file._M_file);\n \t}\n@@ -173,7 +178,7 @@ namespace __format\n \t{\n \t  _M_file._M_bump(__s.size());\n \t  if (_M_add_newline)\n-\t    ::putc_unlocked('\\n', _M_file._M_file);\n+\t    ::putc_unlocked('\\n', _M_file._M_file); // '\\n' triggers a flush\n \t  else if (_M_file._M_line_buffered() && __s.size()\n \t\t     && (__s.back() == '\\n'\n \t\t\t   || __builtin_memchr(__s.data(), '\\n', __s.size())))\n@@ -188,7 +193,13 @@ namespace __format\n   // The file is locked on construction and written to using fwrite_unlocked.\n   class _File_sink final : _Buf_sink<char>\n   {\n-    FILE* _M_file;\n+    struct _File // RAII type to lock/unlock the file.\n+    {\n+      explicit _File(FILE* __f) : _M_file(__f) { ::flockfile(_M_file); }\n+      ~_File() { ::funlockfile(_M_file); }\n+      FILE* _M_file;\n+    } _M_file;\n+\n     bool _M_add_newline;\n \n     // Transfer buffer contents to the FILE, so buffer can be refilled.\n@@ -197,13 +208,13 @@ namespace __format\n     {\n       auto __s = this->_M_used();\n #if _GLIBCXX_HAVE_FWRITE_UNLOCKED\n-      auto __n = ::fwrite_unlocked(__s.data(), 1, __s.size(), _M_file);\n+      auto __n = ::fwrite_unlocked(__s.data(), 1, __s.size(), _M_file._M_file);\n       if (__n != __s.size())\n \t__throw_system_error(errno);\n #else\n       for (char __c : __s)\n-\t::putc_unlocked(__c, _M_file);\n-      if (::ferror(_M_file))\n+\t::putc_unlocked(__c, _M_file._M_file);\n+      if (::ferror(_M_file._M_file))\n \t__throw_system_error(errno);\n #endif\n       this->_M_reset(this->_M_buf);\n@@ -212,14 +223,13 @@ namespace __format\n   public:\n     _File_sink(FILE* __f, bool __add_newline) noexcept\n     : _Buf_sink<char>(), _M_file(__f), _M_add_newline(__add_newline)\n-    { ::flockfile(__f); }\n+    { }\n \n-    ~_File_sink() noexcept(false)\n+    ~_File_sink() noexcept(false) // See above for noexcept(false) rationale.\n     {\n       _File_sink::_M_overflow();\n       if (_M_add_newline)\n-\t::putc_unlocked('\\n', _M_file);\n-      ::funlockfile(_M_file);\n+\t::putc_unlocked('\\n', _M_file._M_file);\n     }\n \n     using _Sink<char>::out;\n@@ -239,14 +249,14 @@ namespace __format\n     : _M_file(__f), _M_add_newline(__add_newline)\n     { }\n \n-    ~_File_sink() noexcept(false)\n+    ~_File_sink() noexcept(false) // See above for noexcept(false) rationale.\n     {\n       string __s = std::move(_M_sink).get();\n       if (_M_add_newline)\n \t__s += '\\n';\n       auto __n = std::fwrite(__s.data(), 1, __s.size(), _M_file);\n       if (__n < __s.size())\n-\t__throw_system_error(EIO);\n+\t__throw_system_error(EIO); // Non-POSIX fwrite doesn't set errno.\n     }\n \n     auto out() { return _M_sink.out(); }\n","prefixes":["committed"]}