[committed] libstdc++: Change return type of std::bit_width to int (LWG 3656)

Message ID 20221125002356.42216-1-jwakely@redhat.com
State Committed
Headers
Series [committed] libstdc++: Change return type of std::bit_width to int (LWG 3656) |

Commit Message

Jonathan Wakely Nov. 25, 2022, 12:23 a.m. UTC
  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
  

Patch

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))> );