Skip to content

Conversation

@eiytoq
Copy link
Contributor

@eiytoq eiytoq commented Jan 6, 2026

Fixes: #171324

@eiytoq eiytoq requested a review from a team as a code owner January 6, 2026 12:28
@github-actions
Copy link

github-actions bot commented Jan 6, 2026

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 6, 2026
@llvmbot
Copy link
Member

llvmbot commented Jan 6, 2026

@llvm/pr-subscribers-libcxx

Author: eiytoq (eiytoq)

Changes

Fixes: #171324


Full diff: https://github.com/llvm/llvm-project/pull/174579.diff

3 Files Affected:

  • (modified) libcxx/docs/Status/Cxx2cIssues.csv (+1-1)
  • (modified) libcxx/include/__numeric/midpoint.h (+3-2)
  • (modified) libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.verify.cpp (+8-7)
diff --git a/libcxx/docs/Status/Cxx2cIssues.csv b/libcxx/docs/Status/Cxx2cIssues.csv
index 9445149a203a2..101a708b7b2de 100644
--- a/libcxx/docs/Status/Cxx2cIssues.csv
+++ b/libcxx/docs/Status/Cxx2cIssues.csv
@@ -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>`__",""
diff --git a/libcxx/include/__numeric/midpoint.h b/libcxx/include/__numeric/midpoint.h
index 2ba80e5cca07d..07ade9d5e1c55 100644
--- a/libcxx/include/__numeric/midpoint.h
+++ b/libcxx/include/__numeric/midpoint.h
@@ -35,8 +35,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER >= 20
 template <class _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<is_integral_v<_Tp> && !is_same_v<bool, _Tp> && !is_null_pointer_v<_Tp>, _Tp>
-midpoint(_Tp __a, _Tp __b) noexcept _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK {
+_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
+    is_integral_v<_Tp> && !is_same_v<bool, __remove_cv_t<_Tp>> && !is_null_pointer_v<_Tp>,
+    _Tp> midpoint(_Tp __a, _Tp __b) noexcept _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK {
   using _Up                = make_unsigned_t<_Tp>;
   constexpr _Up __bitshift = numeric_limits<_Up>::digits - 1;
 
diff --git a/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.verify.cpp b/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.verify.cpp
index 7028e0f32945c..0218770ded4ed 100644
--- a/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.verify.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.verify.cpp
@@ -27,13 +27,14 @@ void       *vp = nullptr;
 
 int main(int, char**)
 {
-    (void) std::midpoint(false, true);  // expected-error {{no matching function for call to 'midpoint'}}
+  (void)std::midpoint(false, true);             // expected-error {{no matching function for call to 'midpoint'}}
+  (void)std::midpoint<const bool>(false, true); // expected-error {{no matching function for call to 'midpoint'}}
 
-//  A couple of odd pointer types that should fail
-    (void) std::midpoint(nullptr, nullptr);  // expected-error {{no matching function for call to 'midpoint'}}
-    (void) std::midpoint(func1, func2);      // expected-error {{no matching function for call to 'midpoint'}}
-    (void) std::midpoint(ip, ip);            // expected-error {{no matching function for call to 'midpoint'}}
-    (void) std::midpoint(vp, vp);            // expected-error {{no matching function for call to 'midpoint'}}
+  //  A couple of odd pointer types that should fail
+  (void)std::midpoint(nullptr, nullptr); // expected-error {{no matching function for call to 'midpoint'}}
+  (void)std::midpoint(func1, func2);     // expected-error {{no matching function for call to 'midpoint'}}
+  (void)std::midpoint(ip, ip);           // expected-error {{no matching function for call to 'midpoint'}}
+  (void)std::midpoint(vp, vp);           // expected-error {{no matching function for call to 'midpoint'}}
 
-    return 0;
+  return 0;
 }

@H-G-Hristov
Copy link
Contributor

I prepared a PR with my suggestions: #174596 which should be merged first eventually.

@eiytoq
Copy link
Contributor Author

eiytoq commented Jan 6, 2026

I prepared a PR with my suggestions: #174596 which should be merged first eventually.

Thanks for putting this together!

@eiytoq
Copy link
Contributor Author

eiytoq commented Jan 7, 2026

Superseded by #174596

@eiytoq eiytoq closed this Jan 7, 2026
@eiytoq eiytoq reopened this Jan 7, 2026
@eiytoq eiytoq force-pushed the libcxx-fix-lwg4265-midpoint branch from 5b60093 to f204544 Compare January 8, 2026 10:56
@H-G-Hristov
Copy link
Contributor

LGTM. Please wait for another maintainer to approve and let us know if you need help with landing this.

@frederick-vs-ja frederick-vs-ja merged commit bfd139d into llvm:main Jan 8, 2026
81 checks passed
@github-actions
Copy link

github-actions bot commented Jan 8, 2026

@eiytoq Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@eiytoq eiytoq deleted the libcxx-fix-lwg4265-midpoint branch January 9, 2026 01:53
kshitijvp pushed a commit to kshitijvp/llvm-project that referenced this pull request Jan 9, 2026
…vm#174579)

Fixes: llvm#171324

---------

Co-authored-by: Hristo Hristov <hghristov.rmm@gmail.com>
Comment on lines +32 to +37
// 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are constraints, so they should really be SFINAE tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. Since this PR is already merged, I will open a follow-up PR to convert these into proper SFINAE tests. I'll also include some general cleanup of midpoint.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was pre-exiting to test constraints of midpoint in .verify.cpp. I think it would be clearer to leave the refactoring in a separated PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LWG4265: std::midpoint should not accept const bool

5 participants