public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r13-4293] libstdc++: Change return type of std::bit_width to int (LWG 3656)
Date: Fri, 25 Nov 2022 00:23:31 +0000 (GMT)	[thread overview]
Message-ID: <20221125002331.3748B3888C42@sourceware.org> (raw)

https://gcc.gnu.org/g:4581328022615c2cb732cfb404151c4b059d26e3

commit r13-4293-g4581328022615c2cb732cfb404151c4b059d26e3
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Nov 24 21:36:07 2022 +0000

    libstdc++: Change return type of std::bit_width to int (LWG 3656)
    
    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.

Diff:
---
 libstdc++-v3/doc/html/manual/bugs.html                    |  4 ++++
 libstdc++-v3/doc/xml/manual/intro.xml                     |  7 +++++++
 libstdc++-v3/include/std/bit                              |  6 ++++--
 .../testsuite/26_numerics/bit/bit.pow.two/lwg3656.cc      | 15 +++++++++++++++
 4 files changed, 30 insertions(+), 2 deletions(-)

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 @@
 	<span class="bold"><strong><code class="code">path::lexically_relative</code> is confused by trailing slashes
 	</strong></span>
     </span></dt><dd><p>Implement the fix for trailing slashes.
+    </p></dd><dt><a id="manual.bugs.dr3656"></a><span class="term"><a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#3656" target="_top">3656</a>:
+	<span class="bold"><strong>Inconsistent bit operations returning a count
+	</strong></span>
+    </span></dt><dd><p>Changed <code class="code">bit_width</code> to return <code class="code">int</code>.
     </p></dd></dl></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="license.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="status.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="setup.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">License </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 2. Setup</td></tr></table></div></body></html>
\ 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.
     <listitem><para>Implement the fix for trailing slashes.
     </para></listitem></varlistentry>
 
+    <varlistentry xml:id="manual.bugs.dr3656"><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&DR;#3656">3656</link>:
+	<emphasis role="bold">Inconsistent bit operations returning a count
+	</emphasis>
+    </term>
+    <listitem><para>Changed <code>bit_width</code> to return <code>int</code>.
+    </para></listitem></varlistentry>
+
   </variablelist>
 
  </section>
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<typename _Tp>
-    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<typename _Tp>
-    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 <bit>
+
+template<typename T> constexpr bool is_int = false;
+template<> constexpr bool is_int<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<decltype(std::bit_width(1u))> );
+static_assert( is_int<decltype(std::bit_width(1ul))> );
+static_assert( is_int<decltype(std::bit_width(1ull))> );
+static_assert( is_int<decltype(std::bit_width((unsigned short)1))> );
+static_assert( is_int<decltype(std::bit_width((unsigned char)1))> );

                 reply	other threads:[~2022-11-25  0:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221125002331.3748B3888C42@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).