From patchwork Fri Nov 25 00:23:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1708913 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=noJDzy68; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NJFwp2JFvz23nT for ; Fri, 25 Nov 2022 11:24:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC2493896C3F for ; Fri, 25 Nov 2022 00:24:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC2493896C3F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669335863; bh=qXHbsxOEHlW0ngkvMkWuM5cjUo5/Afdl1JVue9kJeYw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=noJDzy68ldDrYfEADTvYwz17+OGD3NIGmppv4mFWRlst+ZktazTaNDSej5f/jxvEB qk0pxmAg+xSthcS4Fya4uusy6nFilMUv52w5QBjQaTkZEsP16T6RE15CcNzBos+Djy cqC0IecnDNK6pMS/vJ81DR9eYbRTJnG4B8V0/dsM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 96F603895FF4 for ; Fri, 25 Nov 2022 00:24:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 96F603895FF4 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-495-sDdRtlyENMCf5SyGkLZMqA-1; Thu, 24 Nov 2022 19:24:01 -0500 X-MC-Unique: sDdRtlyENMCf5SyGkLZMqA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A7BAF801755; Fri, 25 Nov 2022 00:23:59 +0000 (UTC) Received: from localhost (unknown [10.33.36.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E6D62166B26; Fri, 25 Nov 2022 00:23:59 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Change return type of std::bit_width to int (LWG 3656) Date: Fri, 25 Nov 2022 00:23:56 +0000 Message-Id: <20221125002356.42216-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, PP_MIME_FAKE_ASCII_TEXT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-linux. Pushed to trunk. -- >8 -- libstdc++-v3/ChangeLog: * doc/html/manual/bugs.html: Regenerate. * doc/xml/manual/intro.xml: Document LWG 3656 change. * include/std/bit (__bit_width, bit_width): Return int. * testsuite/26_numerics/bit/bit.pow.two/lwg3656.cc: New test. --- libstdc++-v3/doc/html/manual/bugs.html | 4 ++++ libstdc++-v3/doc/xml/manual/intro.xml | 7 +++++++ libstdc++-v3/include/std/bit | 6 ++++-- .../26_numerics/bit/bit.pow.two/lwg3656.cc | 15 +++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/lwg3656.cc diff --git a/libstdc++-v3/doc/html/manual/bugs.html b/libstdc++-v3/doc/html/manual/bugs.html index 58600cd6ede..c4a2c26ea39 100644 --- a/libstdc++-v3/doc/html/manual/bugs.html +++ b/libstdc++-v3/doc/html/manual/bugs.html @@ -619,4 +619,8 @@ path::lexically_relative is confused by trailing slashes

Implement the fix for trailing slashes. +

3656: + Inconsistent bit operations returning a count + +

Changed bit_width to return int.

\ No newline at end of file diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index dee01c82159..aee96e37c61 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -1308,6 +1308,13 @@ requirements of the license of GCC. Implement the fix for trailing slashes. + 3656: + Inconsistent bit operations returning a count + + + Changed bit_width to return int. + + diff --git a/libstdc++-v3/include/std/bit b/libstdc++-v3/include/std/bit index 2fd80187210..3e072ef2113 100644 --- a/libstdc++-v3/include/std/bit +++ b/libstdc++-v3/include/std/bit @@ -361,7 +361,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - constexpr _Tp + constexpr int __bit_width(_Tp __x) noexcept { constexpr auto _Nd = __gnu_cxx::__int_traits<_Tp>::__digits; @@ -448,9 +448,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bit_floor(_Tp __x) noexcept { return std::__bit_floor(__x); } + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3656. Inconsistent bit operations returning a count /// The smallest integer greater than the base-2 logarithm of `x`. template - constexpr _If_is_unsigned_integer<_Tp> + constexpr _If_is_unsigned_integer<_Tp, int> bit_width(_Tp __x) noexcept { return std::__bit_width(__x); } diff --git a/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/lwg3656.cc b/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/lwg3656.cc new file mode 100644 index 00000000000..4752c3b1d33 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/lwg3656.cc @@ -0,0 +1,15 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } + +#include + +template constexpr bool is_int = false; +template<> constexpr bool is_int = true; + +// LWG 3656. Inconsistent bit operations returning a count +// Rturn type of std::bit_width(T) changed from T to int. +static_assert( is_int ); +static_assert( is_int ); +static_assert( is_int ); +static_assert( is_int ); +static_assert( is_int );