[libcxx-commits] [libcxx] [libc++] Remove the _LIBCPP_DEPRECATED_ABI_BITSET_CONST_SUBSCRIPT_RETURN_REF opt-out (PR #211313)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 22 09:49:04 PDT 2026
https://github.com/ldionne created https://github.com/llvm/llvm-project/pull/211313
The escape hatch was provided in LLVM 23 to make bitset::operator[] const return __const_reference instead of the conforming bool. There is no evidence it was useful, so remove it as announced for LLVM 24.
>From f18d7b363d3d1a1fa017948717b46aff5649a2c2 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 22 Jul 2026 10:09:22 -0400
Subject: [PATCH] [libc++] Remove the
_LIBCPP_DEPRECATED_ABI_BITSET_CONST_SUBSCRIPT_RETURN_REF opt-out
The escape hatch was provided in LLVM 23 to make bitset::operator[] const
return __const_reference instead of the conforming bool. There is no evidence
it was useful, so remove it as announced for LLVM 24.
---
libcxx/docs/ReleaseNotes/24.rst | 2 +-
libcxx/include/__cxx03/bitset | 5 --
libcxx/include/bitset | 9 ---
.../template.bitset/index_const.pass.cpp | 63 -------------------
4 files changed, 1 insertion(+), 78 deletions(-)
delete mode 100644 libcxx/test/libcxx/utilities/template.bitset/index_const.pass.cpp
diff --git a/libcxx/docs/ReleaseNotes/24.rst b/libcxx/docs/ReleaseNotes/24.rst
index 70c704ff9d326..9154080e6cbbf 100644
--- a/libcxx/docs/ReleaseNotes/24.rst
+++ b/libcxx/docs/ReleaseNotes/24.rst
@@ -67,7 +67,7 @@ ABI Affecting Changes
- TODO: ``std::allocator`` is trivially default constructible since LLVM 22. In LLVM 23, the ``_LIBCPP_DEPRECATED_ABI_NON_TRIVIAL_ALLOCATOR``
macro was provided as an escape hatch, but it has been removed in LLVM 24 since there was no evidence of it being useful.
-- TODO: ``bitset::operator[]`` returns ``bool`` since LLVM 22, fixing a conformance bug. In LLVM 23, the ``_LIBCPP_DEPRECATED_ABI_BITSET_CONST_SUBSCRIPT_RETURN_REF``
+- ``bitset::operator[]`` returns ``bool`` since LLVM 22, fixing a conformance bug. In LLVM 23, the ``_LIBCPP_DEPRECATED_ABI_BITSET_CONST_SUBSCRIPT_RETURN_REF``
macro was provided as an escape hatch, but it has been removed in LLVM 24 since there was no evidence of it being useful.
Build System Changes
diff --git a/libcxx/include/__cxx03/bitset b/libcxx/include/__cxx03/bitset
index f97431dd5fa09..d3a77de410163 100644
--- a/libcxx/include/__cxx03/bitset
+++ b/libcxx/include/__cxx03/bitset
@@ -567,7 +567,6 @@ public:
public:
typedef typename __base::reference reference;
- typedef typename __base::__const_reference __const_reference;
// 23.3.5.1 constructors:
_LIBCPP_HIDE_FROM_ABI bitset() _NOEXCEPT {}
@@ -612,11 +611,7 @@ public:
_LIBCPP_HIDE_FROM_ABI bitset& flip(size_t __pos);
// element access:
-#ifndef _LIBCPP_DEPRECATED_ABI_BITSET_CONST_SUBSCRIPT_RETURN_REF
_LIBCPP_HIDE_FROM_ABI bool operator[](size_t __p) const { return __base::__make_ref(__p); }
-#else
- _LIBCPP_HIDE_FROM_ABI __const_reference operator[](size_t __p) const { return __base::__make_ref(__p); }
-#endif
_LIBCPP_HIDE_FROM_ABI reference operator[](size_t __p) { return __base::__make_ref(__p); }
_LIBCPP_HIDE_FROM_ABI unsigned long to_ulong() const;
_LIBCPP_HIDE_FROM_ABI unsigned long long to_ullong() const;
diff --git a/libcxx/include/bitset b/libcxx/include/bitset
index fd638daea8c73..34a29a92ad9e7 100644
--- a/libcxx/include/bitset
+++ b/libcxx/include/bitset
@@ -618,7 +618,6 @@ public:
static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
typedef __bitset<__n_words, _Size> __base;
typedef typename __base::reference reference;
- typedef typename __base::__const_reference __const_reference;
// 23.3.5.1 constructors:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
@@ -680,18 +679,10 @@ public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip(size_t __pos);
// element access:
- // TODO(LLVM 24): Remove the opt-out
-# ifndef _LIBCPP_DEPRECATED_ABI_BITSET_CONST_SUBSCRIPT_RETURN_REF
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p < _Size, "bitset::operator[] index out of bounds");
return __base::__make_ref(__p);
}
-# else
- [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __const_reference operator[](size_t __p) const {
- _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p < _Size, "bitset::operator[] index out of bounds");
- return __base::__make_ref(__p);
- }
-# endif
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference operator[](size_t __p) {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p < _Size, "bitset::operator[] index out of bounds");
return __base::__make_ref(__p);
diff --git a/libcxx/test/libcxx/utilities/template.bitset/index_const.pass.cpp b/libcxx/test/libcxx/utilities/template.bitset/index_const.pass.cpp
deleted file mode 100644
index 4b2334b8a482b..0000000000000
--- a/libcxx/test/libcxx/utilities/template.bitset/index_const.pass.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// constexpr bool operator[](size_t pos) const; // constexpr since C++23
-
-// Make sure that `_LIBCPP_DEPRECATED_ABI_BITSET_CONST_SUBSCRIPT_RETURN_REF` reverts to the old behaviour.
-
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEPRECATED_ABI_BITSET_CONST_SUBSCRIPT_RETURN_REF
-
-#include <bitset>
-#include <cassert>
-#include <cstddef>
-#include <vector>
-
-#include "../../../std/utilities/template.bitset/bitset_test_cases.h"
-#include "test_macros.h"
-
-template <std::size_t N>
-TEST_CONSTEXPR_CXX23 void test_index_const() {
- std::vector<std::bitset<N> > const cases = get_test_cases<N>();
- for (std::size_t c = 0; c != cases.size(); ++c) {
- std::bitset<N> const v = cases[c];
- if (v.size() > 0) {
- assert(v[N / 2] == v.test(N / 2));
- }
- }
- ASSERT_SAME_TYPE(decltype(cases[0][0]), typename std::bitset<N>::__const_reference);
-}
-
-TEST_CONSTEXPR_CXX23 bool test() {
- test_index_const<0>();
- test_index_const<1>();
- test_index_const<31>();
- test_index_const<32>();
- test_index_const<33>();
- test_index_const<63>();
- test_index_const<64>();
- test_index_const<65>();
-
- std::bitset<1> set_;
- set_[0] = false;
- const auto& set = set_;
- auto b = set[0];
- set_[0] = true;
- assert(b);
-
- return true;
-}
-
-int main(int, char**) {
- test();
- test_index_const<1000>(); // not in constexpr because of constexpr evaluation step limits
-#if TEST_STD_VER > 20
- static_assert(test());
-#endif
-
- return 0;
-}
More information about the libcxx-commits
mailing list