]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Extend constexpr if to C++14 in _Hashtable::_S_nothrow_move()
authorJonathan Wakely <jwakely@redhat.com>
Wed, 8 Oct 2025 14:26:54 +0000 (15:26 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 9 Oct 2025 14:26:08 +0000 (15:26 +0100)
We can use diagnostic pragmas to allow the constexpr if version of this
function to be used for C++14 as well. We still need the __and_ version
for C++11 because we can't use 'if' in constexpr functions at all before
C++14.

Also use the integral_constant::value static data member instead of
invoking integral_constant::operator(), as it's a tiny bit cheaper to
compiler.

libstdc++-v3/ChangeLog:

* include/bits/hashtable.h (_Hashtable::_S_nothrow_move): Use
diagnostic pragmas to allow constexpr if in C++14. Use value
member instead of operator().

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
libstdc++-v3/include/bits/hashtable.h

index 20f9bd98d5b7796f5d4b3a1d1967073f9b74b7bb..b5a71f516f88100139d6948d3497f613106aca09 100644 (file)
@@ -477,15 +477,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        static constexpr bool
        _S_nothrow_move()
        {
-#if __cplusplus <= 201402L
+#if __cpp_constexpr >= 201304 // >= C++14
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr
+         if constexpr (_No_realloc)
+           if constexpr (is_nothrow_copy_constructible<_Hash>::value)
+             return is_nothrow_copy_constructible<_Equal>::value;
+         return false;
+# pragma GCC diagnostic pop
+#else // In C++11 a constexpr function must be a single statement.
          return __and_<__bool_constant<_No_realloc>,
                        is_nothrow_copy_constructible<_Hash>,
                        is_nothrow_copy_constructible<_Equal>>::value;
-#else
-         if constexpr (_No_realloc)
-           if constexpr (is_nothrow_copy_constructible<_Hash>())
-             return is_nothrow_copy_constructible<_Equal>();
-         return false;
 #endif
        }