[gcc r10-9046] libstdc++: Fix macro redefinition warnings

Jonathan Wakely redi@gcc.gnu.org
Wed Nov 18 13:03:56 GMT 2020


https://gcc.gnu.org/g:82fbb61820ccfd6217cd0ed6faacc451c409ee73

commit r10-9046-g82fbb61820ccfd6217cd0ed6faacc451c409ee73
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Sep 10 18:51:24 2020 +0100

    libstdc++: Fix macro redefinition warnings
    
    Including <version> after <iterator> gives a warning about redefining
    the __cpp_lib_array_constexpr macro. What happens is that <iterator>
    sets the C++20 value, then <version> redefines it to the C++17 value,
    then undefines it and defines it again to the C++20 value.
    
    This change avoids defining it to the C++17 value when compiling C++20
    or later (which also means we no longer need the #undef).
    
    A similar warning happens for __cpp_lib_constexpr_char_traits when
    including <version> after any header that includes <bits/char_traits.h>.
    
    libstdc++-v3/ChangeLog:
    
            * include/std/version (__cpp_lib_array_constexpr)
            (__cpp_lib_constexpr_char_traits): Only define C++17 value when
            compiling C++17.
    
    (cherry picked from commit f903c13ce8674c623f176eaf4516505205fefcf6)

Diff:
---
 libstdc++-v3/include/std/version | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version
index 758b121571b..1cb2e4edb75 100644
--- a/libstdc++-v3/include/std/version
+++ b/libstdc++-v3/include/std/version
@@ -122,12 +122,16 @@
 #if _GLIBCXX_HOSTED
 #define __cpp_lib_any 201606L
 #define __cpp_lib_apply 201603
-#define __cpp_lib_array_constexpr 201803L
+#if __cplusplus == 201703L // N.B. updated value in C++20
+# define __cpp_lib_array_constexpr 201803L
+#endif
 #define __cpp_lib_as_const 201510
 #define __cpp_lib_boyer_moore_searcher 201603
 #define __cpp_lib_chrono 201611
 #define __cpp_lib_clamp 201603
-#define __cpp_lib_constexpr_char_traits 201611L
+#if __cplusplus == 201703L // N.B. updated value in C++20
+# define __cpp_lib_constexpr_char_traits 201611L
+#endif
 #define __cpp_lib_enable_shared_from_this 201603
 #define __cpp_lib_execution 201902L // FIXME: should be 201603L
 #define __cpp_lib_filesystem 201703
@@ -190,8 +194,6 @@
 #define __cpp_lib_unwrap_ref 201811L
 
 #if _GLIBCXX_HOSTED
-#undef __cpp_lib_array_constexpr
-#undef __cpp_lib_constexpr_char_traits
 #define __cpp_lib_array_constexpr 201811L
 #define __cpp_lib_assume_aligned 201811L
 #define __cpp_lib_bind_front 201907L


More information about the Libstdc++-cvs mailing list