[libcxx-commits] [libcxx] [libc++] Fix possible out of range access in bitset (PR #121348)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 11 10:00:27 PDT 2025


================
@@ -507,8 +527,11 @@ inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0)
 
 template <size_t _Size>
 inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
-    : __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v)
-                                        : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)) {}
+    // TODO: This is a workaround for a gdb test failure (gdb_pretty_printer_test.sh.cpp) in
+    // stage1 CI (generic-gcc, gcc-14, g++-14), due to the __bits_per_word name lookup failure
+    // if not referenced in the constructor initializer list.
+    // See: https://github.com/llvm/llvm-project/actions/runs/15071518915/job/42368867929?pr=121348#logs
----------------
ldionne wrote:

```suggestion
    // TODO: We must refer to __bits_per_word in order to work around an issue with the GDB pretty-printers.
    //       Without it, the pretty-printers complain about a missing __bits_per_word member. This must
    //       be investigated.
```

https://github.com/llvm/llvm-project/pull/121348


More information about the libcxx-commits mailing list