]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Swap expressions in noexcept-specifier of ranges::not_equal_to
authorJonathan Wakely <jwakely@redhat.com>
Thu, 12 Dec 2024 23:24:39 +0000 (23:24 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 13 Dec 2024 13:04:37 +0000 (13:04 +0000)
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.

libstdc++-v3/include/bits/ranges_cmp.h
libstdc++-v3/testsuite/20_util/function_objects/range.cmp/not_equal_to.cc

index 8425016288cd4616efc0858ebafd2c71ff1b1fa5..b1a33f48d02d0b17e60704249af01877b81d24a1 100644 (file)
@@ -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;
index 5b4f3cb32ffdfdb567f3cb6b9677297a2139170d..1b5167f97838ab817a49355d0a76cab8480a9323 100644 (file)
@@ -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();
 }