[{"id":3682069,"web_url":"http://patchwork.ozlabs.org/comment/3682069/","msgid":"<CACb0b4kjp2FhyWF7inC8Z7YtKp3m+7GUJLsO4w78vN5SQmzfDA@mail.gmail.com>","list_archive_url":null,"date":"2026-04-24T15:03:07","subject":"Re: [PATCH] libstdc++: Disallow duration of cv-qualified types and\n references.","submitter":{"id":48004,"url":"http://patchwork.ozlabs.org/api/people/48004/","name":"Jonathan Wakely","email":"jwakely@redhat.com"},"content":"On Fri, 24 Apr 2026 at 15:59, Tomasz Kamiński <tkaminsk@redhat.com> wrote:\n>\n> This implements LWG 4481, \"Disallow chrono::duration<const T, P>\",\n> which was approved in Croydon 2026.\n>\n> libstdc++-v3/ChangeLog:\n>\n>         * include/bits/chrono.h: Add static_assert requiring cv-unqualified\n>         non-reference type.\n>         * testsuite/20_util/duration/io.cc: Remove test for duration\n>         with const rep.\n>         * testsuite/20_util/duration/requirements/typedefs_neg4.cc:\n>         New test.\n> ---\n> Testing on x86_64-linux. All *duration* tests passed in all standard modes.\n> OK for trunk when all test passes?\n>\n>  libstdc++-v3/include/bits/chrono.h                 |  4 ++++\n>  libstdc++-v3/testsuite/20_util/duration/io.cc      | 14 --------------\n>  .../20_util/duration/requirements/typedefs_neg4.cc | 11 +++++++++++\n>  3 files changed, 15 insertions(+), 14 deletions(-)\n>  create mode 100644 libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg4.cc\n>\n> diff --git a/libstdc++-v3/include/bits/chrono.h b/libstdc++-v3/include/bits/chrono.h\n> index fd91505c16f..d639cfaa485 100644\n> --- a/libstdc++-v3/include/bits/chrono.h\n> +++ b/libstdc++-v3/include/bits/chrono.h\n> @@ -514,6 +514,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n>      template<typename _Rep, typename _Period>\n>        class duration\n>        {\n> +       // _GLIBCXX_RESOLVE_LIB_DEFECTS\n> +       // 4481. Disallow chrono::duration<const T, P>\n> +       static_assert(is_same<_Rep, __remove_cvref_t<_Rep>>::value,\n> +                     \"rep should be cv-unqualified object type\");\n>         static_assert(!__is_duration<_Rep>::value,\n>                       \"rep cannot be a std::chrono::duration\");\n>         static_assert(__is_ratio<_Period>::value,\n> diff --git a/libstdc++-v3/testsuite/20_util/duration/io.cc b/libstdc++-v3/testsuite/20_util/duration/io.cc\n> index 6ada4fcfa84..463d9feb21f 100644\n> --- a/libstdc++-v3/testsuite/20_util/duration/io.cc\n> +++ b/libstdc++-v3/testsuite/20_util/duration/io.cc\n> @@ -38,13 +38,6 @@ test01()\n>    ss << duration<char16_t>(126) << ' ';\n>    ss << duration<char32_t>(127) << ' ';\n>    VERIFY( ss.str() == \"121s 122s 123s 124s 125s 126s 127s \" );\n> -\n> -  ss.str(\"\");\n> -  ss << std::hex << std::uppercase << duration<const char>(0x1A) << ' ';\n> -  ss << std::hex << std::uppercase << duration<const wchar_t>(0x2A) << ' ';\n> -  ss << std::hex << std::uppercase << duration<signed char>(0x3A) << ' ';\n\nThis line isn't a cv-qualified type. Is it redundant with other checks above?\nWe could just remove the 'const' from these lines.\n\n> -  ss << std::scientific << duration<const double>(4.5) << ' ';\n> -  VERIFY( ss.str() == \"1As 2As 3As 4.500000E+00s \" );\n>  }\n>\n>  void\n> @@ -77,13 +70,6 @@ test02()\n>    ss << duration<char16_t>(126) << ' ';\n>    ss << duration<char32_t>(127) << ' ';\n>    VERIFY( ss.str() == L\"121s 122s 123s 124s 125s 126s 127s \" );\n> -\n> -  ss.str(L\"\");\n> -  ss << std::hex << std::uppercase << duration<const char>(0x1A) << ' ';\n> -  ss << std::hex << std::uppercase << duration<const wchar_t>(0x2A) << ' ';\n> -  ss << std::hex << std::uppercase << duration<signed char>(0x3A) << ' ';\n> -  ss << std::scientific << duration<const double>(4.5) << ' ';\n> -  VERIFY( ss.str() == L\"1As 2As 3As 4.500000E+00s \" );\n>  #endif\n>  }\n>\n> diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg4.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg4.cc\n> new file mode 100644\n> index 00000000000..52a5d92cc8b\n> --- /dev/null\n> +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg4.cc\n> @@ -0,0 +1,11 @@\n> +// { dg-do compile { target c++11 } }\n> +\n> +#include <chrono>\n> +\n> +const int i = 10;\n> +// Check if rep is a cv-unqualifed object type\n> +std::chrono::duration<const int> d1(i); // { dg-error \"required from here\" }\n> +std::chrono::duration<volatile int> d2(i); // { dg-error \"required from here\" }\n> +std::chrono::duration<const int&> d3(i); // { dg-error \"required from here\" }\n> +\n> +// { dg-error \"rep should be cv-unqualified object type\" \"\" { target *-*-* } 0 }\n> --\n> 2.53.0\n>","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=dU0GEfM9;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.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=dU0GEfM9","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.133.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org [38.145.34.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 4g2GSd1tr2z1yDD\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 25 Apr 2026 01:03:59 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id DF91F4BB58F4\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 24 Apr 2026 15:03:57 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n by sourceware.org (Postfix) with ESMTP id E3F054BA902C\n for <gcc-patches@gcc.gnu.org>; Fri, 24 Apr 2026 15:03:29 +0000 (GMT)","from mail-pg1-f198.google.com (mail-pg1-f198.google.com\n [209.85.215.198]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-58-qseF90XjPCeqwNG6TskowA-1; Fri, 24 Apr 2026 11:03:27 -0400","by mail-pg1-f198.google.com with SMTP id\n 41be03b00d2f7-c79907d4c57so2544380a12.0\n for <gcc-patches@gcc.gnu.org>; Fri, 24 Apr 2026 08:03:26 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org DF91F4BB58F4","OpenDKIM Filter v2.11.0 sourceware.org E3F054BA902C"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org E3F054BA902C","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org E3F054BA902C","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777043010; cv=none;\n b=IGKdEAfFHyZzPOBqAP/QmE2iMy70393HMkRFO603ib8I1D2EdZY2F7YN7vizfsJ66G+SMJUANivRxxksrky0f7hg3yHrJP0/GnMXeA+OpUDvjsUlkYktiBXHljU/zxb/xsS8B8KJZJaCSPvI5PVWhxB8p4OuUoEx5h/59tdmvQw=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777043010; c=relaxed/simple;\n bh=8gM6ax3hCAaRsWoOPuSeTgu/lLnHD8kHq//3eK7+sVg=;\n h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To;\n b=J/5pec3e5IWzWDarxLwZJhkMXxPaXO1xlSLTr7mekAZ7AVVGP+Bq/J91aoFVnDqYLXZziFUFLJJ3n//T+LB0uTydMHz33yzZPjfqSPy5qYM4cQDp1rD0e82m38nLKGkiq4/POvqj7uN3P7AAxGtnQ+HpsZvBny78Ag9mzq1PjU8=","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=1777043009;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=ke95hzPWgYJiWZKaKmx3jsJq9RkHdw5C0j+G/RoEWc8=;\n b=dU0GEfM9c52a9yBoJVY1ezvyzDa/ODFdQsMfJloi3zFsgeXM7+tYo1Ziy2aysnaXcK1cOv\n jwf9yX1L34RPEPHSbKl+7HgYYajZf3qG0hQCaYjif6sG/+pkvCKhU4fekXG3hcSqLoFqNE\n 3x0zRE/V12AJJTfOLCVQFKIo2krqVxw=","X-MC-Unique":"qseF90XjPCeqwNG6TskowA-1","X-Mimecast-MFC-AGG-ID":"qseF90XjPCeqwNG6TskowA_1777043006","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777043006; x=1777647806;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=ke95hzPWgYJiWZKaKmx3jsJq9RkHdw5C0j+G/RoEWc8=;\n b=iBIKyfVKlAamwAtGb9tYkLbTKNPPpvLJcnuqP2/iGBZKEo+AjWTh3d0TSkQA68DcqV\n hsG45y1RHPPEZKRCe+ugX8C2pmK6czQWsy3Gr+DwQVOhAdeYGY72wNvr/PQN63yuAvyg\n pq7YhozKBdgjgBuh+IT4a8MTKiDofFHpr7P/FygEJ1hw+0nLUwKkYy5xyOO/UPWOmkoR\n MYYMuqnNGkdBcKXHX7wMUjs+ZKGCNttvK6My17WkWUdBnVa3TNAKwY/ygdjng1XWK0b/\n x6kyNuTPLu++cvPTl0VZ+MWXgN4G4rajbQ//p02nNzZy+HlHlypy3gLjd83nPdBBvfjM\n BD5A==","X-Forwarded-Encrypted":"i=1;\n AFNElJ82rotXwZ1ieZeHfE6FA90IAfS93h/EYXKqCYBx++3/pMJBTtMmE0+O1qc9v67PGre9CbLNlwiqBEcZxw==@gcc.gnu.org","X-Gm-Message-State":"AOJu0Yz7zIm+lMhqjV2JaOF/UICxxRhfIeaH79oRd/vpwv8AsyBdQpcX\n daANJ0VaqZvIpBXUQcxt7zlyS5pou6EA3hCFcbKyR22JSQExGJYH3Vho/XkLg7vrWq6NjUtAItR\n qF2eJUy3vE6wnG7Kb3RK9rU/DelGg0LqbfhsWTluMxnqB0f/C/HmT1suypHlZTGWoOzoZUnNvrZ\n 2pv358+vHRqo1p47PUeQy1BVN/j7M9P1h63A==","X-Gm-Gg":"AeBDievo9g5UWrCgOXo2TrGKfmrZM/G964d1XzXemmHjlKrQvhUNWRxEAsIDcH9u6yM\n qF3JoyfOhPX0DBj6AyX74tf8MMIuSyNhJXLmFR79MUR7lu3L+I8uOPlz1OqT19oWYYq4tiUzJCA\n hTC2FP0ydXinhPjiG+n9J/TlFg/OU6deS74xqrfbvFohwD6ZkGtSLJTxywwSTlCvjQJLgXInMBL\n qdCYA0N5M9SoBTmWHnlQY3OIL+6KCrKLlWD0dPZZ7qzkXoY+fmisEzWaw3xj82YOqSXZhX3yEcD\n Dg==","X-Received":["by 2002:a05:6a20:734d:b0:39f:441:493c with SMTP id\n adf61e73a8af0-3a08d8925c6mr36039960637.30.1777043005909;\n Fri, 24 Apr 2026 08:03:25 -0700 (PDT)","by 2002:a05:6a20:734d:b0:39f:441:493c with SMTP id\n adf61e73a8af0-3a08d8925c6mr36039903637.30.1777043005318; Fri, 24 Apr 2026\n 08:03:25 -0700 (PDT)"],"MIME-Version":"1.0","References":"<20260424145837.2218574-1-tkaminsk@redhat.com>","In-Reply-To":"<20260424145837.2218574-1-tkaminsk@redhat.com>","From":"Jonathan Wakely <jwakely@redhat.com>","Date":"Fri, 24 Apr 2026 16:03:07 +0100","X-Gm-Features":"AQROBzACTCiZEeiB2xfyIsRqB8G_3H1X274euFSJldSNxx0dfQgzHGWhlcM9aEM","Message-ID":"\n <CACb0b4kjp2FhyWF7inC8Z7YtKp3m+7GUJLsO4w78vN5SQmzfDA@mail.gmail.com>","Subject":"Re: [PATCH] libstdc++: Disallow duration of cv-qualified types and\n references.","To":"=?utf-8?q?Tomasz_Kami=C5=84ski?= <tkaminsk@redhat.com>","Cc":"libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"w0ask5u2jEa4nce3lJPzWceuxq-Fpx1L5yTYm8G447U_1777043006","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","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"}}]