[libc++] Fix LWG 4265: std::midpoint should not accept const bool (#174579)

Fixes: #171324

---------

Co-authored-by: Hristo Hristov <hghristov.rmm@gmail.com>
This commit is contained in:
eiytoq 2026-01-09 07:26:38 +08:00 committed by GitHub
parent f90cbc61af
commit bfd139dacd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 2 deletions

View File

@ -164,7 +164,7 @@
"`LWG4256 <https://wg21.link/LWG4256>`__","Incorrect constrains for ``function_ref`` constructors from ``nontype_t``","2025-11 (Kona)","","","`#171321 <https://github.com/llvm/llvm-project/issues/171321>`__",""
"`LWG4257 <https://wg21.link/LWG4257>`__","Stream insertion for ``chrono::local_time`` should be constrained","2025-11 (Kona)","","","`#171322 <https://github.com/llvm/llvm-project/issues/171322>`__",""
"`LWG4260 <https://wg21.link/LWG4260>`__","Query objects must be default constructible","2025-11 (Kona)","","","`#171323 <https://github.com/llvm/llvm-project/issues/171323>`__",""
"`LWG4265 <https://wg21.link/LWG4265>`__","``std::midpoint`` should not accept ``const bool``","2025-11 (Kona)","","","`#171324 <https://github.com/llvm/llvm-project/issues/171324>`__",""
"`LWG4265 <https://wg21.link/LWG4265>`__","``std::midpoint`` should not accept ``const bool``","2025-11 (Kona)","|Complete|","22","`#171324 <https://github.com/llvm/llvm-project/issues/171324>`__",""
"`LWG4266 <https://wg21.link/LWG4266>`__","``layout_stride::mapping`` should treat empty mappings as exhaustive","2025-11 (Kona)","","","`#171325 <https://github.com/llvm/llvm-project/issues/171325>`__",""
"`LWG4269 <https://wg21.link/LWG4269>`__","``unique_copy`` passes arguments to its predicate backwards","2025-11 (Kona)","","","`#171326 <https://github.com/llvm/llvm-project/issues/171326>`__",""
"`LWG4272 <https://wg21.link/LWG4272>`__","For ``rank == 0``, ``layout_stride`` is atypically convertible","2025-11 (Kona)","","","`#171327 <https://github.com/llvm/llvm-project/issues/171327>`__",""

1 Issue # Issue Name Meeting Status First released version GitHub issue Notes
164 `LWG4256 <https://wg21.link/LWG4256>`__ Incorrect constrains for ``function_ref`` constructors from ``nontype_t`` 2025-11 (Kona) `#171321 <https://github.com/llvm/llvm-project/issues/171321>`__
165 `LWG4257 <https://wg21.link/LWG4257>`__ Stream insertion for ``chrono::local_time`` should be constrained 2025-11 (Kona) `#171322 <https://github.com/llvm/llvm-project/issues/171322>`__
166 `LWG4260 <https://wg21.link/LWG4260>`__ Query objects must be default constructible 2025-11 (Kona) `#171323 <https://github.com/llvm/llvm-project/issues/171323>`__
167 `LWG4265 <https://wg21.link/LWG4265>`__ ``std::midpoint`` should not accept ``const bool`` 2025-11 (Kona) |Complete| 22 `#171324 <https://github.com/llvm/llvm-project/issues/171324>`__
168 `LWG4266 <https://wg21.link/LWG4266>`__ ``layout_stride::mapping`` should treat empty mappings as exhaustive 2025-11 (Kona) `#171325 <https://github.com/llvm/llvm-project/issues/171325>`__
169 `LWG4269 <https://wg21.link/LWG4269>`__ ``unique_copy`` passes arguments to its predicate backwards 2025-11 (Kona) `#171326 <https://github.com/llvm/llvm-project/issues/171326>`__
170 `LWG4272 <https://wg21.link/LWG4272>`__ For ``rank == 0``, ``layout_stride`` is atypically convertible 2025-11 (Kona) `#171327 <https://github.com/llvm/llvm-project/issues/171327>`__

View File

@ -18,6 +18,7 @@
#include <__type_traits/is_same.h>
#include <__type_traits/is_void.h>
#include <__type_traits/make_unsigned.h>
#include <__type_traits/remove_cv.h>
#include <limits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@ -31,7 +32,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
template <class _Tp>
requires(is_integral_v<_Tp> && !is_same_v<_Tp, bool>)
requires(is_integral_v<_Tp> && !is_same_v<remove_cv_t<_Tp>, bool>)
[[nodiscard]]
_LIBCPP_HIDE_FROM_ABI constexpr _Tp midpoint(_Tp __a, _Tp __b) noexcept _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK {
using _Up = make_unsigned_t<_Tp>;

View File

@ -29,6 +29,12 @@ void* vp = nullptr;
void test() {
// expected-error@+1 {{no matching function for call to 'midpoint'}}
(void)std::midpoint(false, true);
// expected-error@+1 {{no matching function for call to 'midpoint'}}
(void)std::midpoint<const bool>(false, true);
// expected-error@+1 {{no matching function for call to 'midpoint'}}
(void)std::midpoint<const volatile bool>(false, true);
// expected-error@+1 {{no matching function for call to 'midpoint'}}
(void)std::midpoint<volatile bool>(false, true);
// A couple of odd pointer types that should fail
(void)std::midpoint(nullptr, nullptr); // expected-error {{no matching function for call to 'midpoint'}}