]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix redefinition error in std::tuple [PR108822]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 15 Jan 2024 16:51:39 +0000 (16:51 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 15 Jan 2024 17:18:53 +0000 (17:18 +0000)
When using a compiler that doesn't define __cpp_conditional_explicit
there's a redefinition error for tuple::__nothrow_assignable. This is
because it's defined in different places for the pre-C++20 and C++20
implementations, which are controled by different preprocessor
conditions. For certain combinations of C++20 feature test macros it's
possible for both __nothrow_assignable definitions to be in scope.

Move the pre-C++20 __assignable and __nothrow_assignable definitions adjacent to
their use, so that only one set of definitions is visible for any given
set of feature test macros.

libstdc++-v3/ChangeLog:

PR libstdc++/108822
* include/std/tuple (__assignable, __is_nothrow_assignable):
Move pre-C++20 definitions adjacent to their use.

libstdc++-v3/include/std/tuple

index 5f4a393b532c19041cad3a0aa998f5b4ae229af3..2f6e419ea5bf13d1eac05e088c00e997d49f5e23 100644 (file)
@@ -1237,20 +1237,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          _TCC<_Cond>::template __is_explicitly_constructible<_Args...>(),
          bool>;
 
-      template<typename... _UElements>
-       static constexpr
-       __enable_if_t<sizeof...(_UElements) == sizeof...(_Elements), bool>
-       __assignable()
-       { return __and_<is_assignable<_Elements&, _UElements>...>::value; }
-
-      // Condition for noexcept-specifier of an assignment operator.
-      template<typename... _UElements>
-       static constexpr bool __nothrow_assignable()
-       {
-         return
-           __and_<is_nothrow_assignable<_Elements&, _UElements>...>::value;
-       }
-
       // Condition for noexcept-specifier of a constructor.
       template<typename... _UElements>
        static constexpr bool __nothrow_constructible()
@@ -1685,7 +1671,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        operator=(_UTuple&& __u) const;
 #endif // C++23
 
-#else // ! concepts
+#else // ! (concepts && consteval)
+
+    private:
+      template<typename... _UElements>
+       static constexpr
+       __enable_if_t<sizeof...(_UElements) == sizeof...(_Elements), bool>
+       __assignable()
+       { return __and_<is_assignable<_Elements&, _UElements>...>::value; }
+
+      // Condition for noexcept-specifier of an assignment operator.
+      template<typename... _UElements>
+       static constexpr bool __nothrow_assignable()
+       {
+         return
+           __and_<is_nothrow_assignable<_Elements&, _UElements>...>::value;
+       }
+
+    public:
 
       _GLIBCXX20_CONSTEXPR
       tuple&
@@ -1728,7 +1731,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          this->_M_assign(std::move(__in));
          return *this;
        }
-#endif // concepts
+#endif // concepts && consteval
 
       // tuple swap
       _GLIBCXX20_CONSTEXPR