https://gcc.gnu.org/g:233860f005ccd76c7604cf0eac18b9eda3d984f4

commit r15-6221-g233860f005ccd76c7604cf0eac18b9eda3d984f4
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Thu Dec 12 23:24:39 2024 +0000

    libstdc++: Swap expressions in noexcept-specifier of ranges::not_equal_to
    
    Although this should never make a difference for sensible code, we
    should really make the expression in the noexcept-specifier match the
    expression in the function body.
    
    libstdc++-v3/ChangeLog:
    
            * include/bits/ranges_cmp.h (not_equal_to): Make order of
            expressions in noexcept-specifier match the body.
            * testsuite/20_util/function_objects/range.cmp/not_equal_to.cc:
            Check noexcept.

Diff:
---
 libstdc++-v3/include/bits/ranges_cmp.h                  |  2 +-
 .../20_util/function_objects/range.cmp/not_equal_to.cc  | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/ranges_cmp.h 
b/libstdc++-v3/include/bits/ranges_cmp.h
index 8425016288cd..b1a33f48d02d 100644
--- a/libstdc++-v3/include/bits/ranges_cmp.h
+++ b/libstdc++-v3/include/bits/ranges_cmp.h
@@ -99,7 +99,7 @@ namespace ranges
       requires equality_comparable_with<_Tp, _Up>
       constexpr bool
       operator()(_Tp&& __t, _Up&& __u) const
-      noexcept(noexcept(std::declval<_Up>() == std::declval<_Tp>()))
+      noexcept(noexcept(std::declval<_Tp>() == std::declval<_Up>()))
       { return !equal_to{}(std::forward<_Tp>(__t), std::forward<_Up>(__u)); }
 
     using is_transparent = __is_transparent;
diff --git 
a/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/not_equal_to.cc 
b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/not_equal_to.cc
index 5b4f3cb32ffd..1b5167f97838 100644
--- a/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/not_equal_to.cc
+++ b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/not_equal_to.cc
@@ -68,9 +68,26 @@ test02()
   VERIFY( ! f(x, x) );
 }
 
+struct A
+{
+  bool operator==(const A&) const noexcept { return true; }
+  bool operator==(A&&) const { return true; }
+};
+
+void
+test03()
+{
+  const A a{};
+  static_assert( noexcept(a == a) );
+  static_assert( ! noexcept(a == A{}) );
+  static_assert( noexcept(std::ranges::not_equal_to{}(a, a)) );
+  static_assert( ! noexcept(std::ranges::not_equal_to{}(a, A{})) );
+}
+
 int
 main()
 {
   test01();
   test02();
+  test03();
 }

Reply via email to