public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Suppress redundant definitions of inline variables
@ 2021-08-03 15:34 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-08-03 15:34 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 710 bytes --]

In C++17 the out-of-class definitions for static constexpr variables are
redundant, because they are implicitly inline. This change avoids
"redundant redeclaration" warnings from -Wsystem-headers -Wdeprecated.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	* include/bits/random.tcc (linear_congruential_engine): Do not
	define static constexpr members when they are implicitly inline.
	* include/std/ratio (ratio, __ratio_multiply, __ratio_divide)
	(__ratio_add, __ratio_subtract): Likewise.
	* include/std/type_traits (integral_constant): Likewise.
	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
	line number.

Tested powerpc64le-linux. Committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 5039 bytes --]

commit a77a46d9aeb0166b4b1ee4b52e1cbb4b52c6736f
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Aug 3 15:03:44 2021

    libstdc++: Suppress redundant definitions of inline variables
    
    In C++17 the out-of-class definitions for static constexpr variables are
    redundant, because they are implicitly inline. This change avoids
    "redundant redeclaration" warnings from -Wsystem-headers -Wdeprecated.
    
    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
    
    libstdc++-v3/ChangeLog:
    
            * include/bits/random.tcc (linear_congruential_engine): Do not
            define static constexpr members when they are implicitly inline.
            * include/std/ratio (ratio, __ratio_multiply, __ratio_divide)
            (__ratio_add, __ratio_subtract): Likewise.
            * include/std/type_traits (integral_constant): Likewise.
            * testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
            line number.

diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc
index 6ba263072b0..0be50d90e8a 100644
--- a/libstdc++-v3/include/bits/random.tcc
+++ b/libstdc++-v3/include/bits/random.tcc
@@ -91,6 +91,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   } // namespace __detail
   /// @endcond
 
+#if ! __cpp_inline_variables
   template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
     constexpr _UIntType
     linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier;
@@ -106,6 +107,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
     constexpr _UIntType
     linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
+#endif
 
   /**
    * Seeds the LCR with integral value @p __s, adjusted so that the
diff --git a/libstdc++-v3/include/std/ratio b/libstdc++-v3/include/std/ratio
index ceee7d00c12..92f6d4b9ea1 100644
--- a/libstdc++-v3/include/std/ratio
+++ b/libstdc++-v3/include/std/ratio
@@ -279,11 +279,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       typedef ratio<num, den> type;
     };
 
+#if ! __cpp_inline_variables
   template<intmax_t _Num, intmax_t _Den>
     constexpr intmax_t ratio<_Num, _Den>::num;
 
   template<intmax_t _Num, intmax_t _Den>
     constexpr intmax_t ratio<_Num, _Den>::den;
+#endif
 
   /// @cond undocumented
 
@@ -307,11 +309,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       static constexpr intmax_t den = type::den;
     };
 
+#if ! __cpp_inline_variables
   template<typename _R1, typename _R2>
     constexpr intmax_t __ratio_multiply<_R1, _R2>::num;
 
   template<typename _R1, typename _R2>
     constexpr intmax_t __ratio_multiply<_R1, _R2>::den;
+#endif
 
   /// @endcond
 
@@ -334,11 +338,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       static constexpr intmax_t den = type::den;
     };
 
+#if ! __cpp_inline_variables
   template<typename _R1, typename _R2>
     constexpr intmax_t __ratio_divide<_R1, _R2>::num;
 
   template<typename _R1, typename _R2>
     constexpr intmax_t __ratio_divide<_R1, _R2>::den;
+#endif
 
   /// @endcond
 
@@ -512,11 +518,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       static constexpr intmax_t den = type::den;
     };
 
+#if ! __cpp_inline_variables
   template<typename _R1, typename _R2>
     constexpr intmax_t __ratio_add<_R1, _R2>::num;
 
   template<typename _R1, typename _R2>
     constexpr intmax_t __ratio_add<_R1, _R2>::den;
+#endif
 
   /// @endcond
 
@@ -537,11 +545,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       static constexpr intmax_t den = type::den;
     };
 
+#if ! __cpp_inline_variables
   template<typename _R1, typename _R2>
     constexpr intmax_t __ratio_subtract<_R1, _R2>::num;
 
   template<typename _R1, typename _R2>
     constexpr intmax_t __ratio_subtract<_R1, _R2>::den;
+#endif
 
   /// @endcond
 
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 0d821f9c074..46edde905f8 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -73,8 +73,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
     };
 
+#if ! __cpp_inline_variables
   template<typename _Tp, _Tp __v>
     constexpr _Tp integral_constant<_Tp, __v>::value;
+#endif
 
   /// The type used as a compile-time boolean with true value.
   using true_type =  integral_constant<bool, true>;
diff --git a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
index d6e6399bd79..8fba7144d8a 100644
--- a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
+++ b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
@@ -12,4 +12,4 @@ auto x = std::generate_canonical<std::size_t,
 
 // { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 169 }
 
-// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 3350 }
+// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 3352 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-03 15:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 15:34 [committed] libstdc++: Suppress redundant definitions of inline variables Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).