public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed 2/5] libstdc++: Fix macro redefinition warnings
Date: Thu, 10 Sep 2020 19:19:17 +0100	[thread overview]
Message-ID: <20200910181917.GI6061@redhat.com> (raw)
In-Reply-To: <20200910181733.GA85317@redhat.com>

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

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.


Tested powerpc64le-linux. Committed to trunk.



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

commit f903c13ce8674c623f176eaf4516505205fefcf6
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Sep 10 18:51:24 2020

    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.

diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version
index f64aff4f520..d5d42ed0a72 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
@@ -191,8 +195,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

  parent reply	other threads:[~2020-09-10 18:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-10 18:17 [committed 1/5] libstdc++: Fix -Wnarrowing warnings Jonathan Wakely
2020-09-10 18:18 ` [committed 2/5] libstdc++: Fix -Wdeprecated-declarations warnings Jonathan Wakely
2020-09-10 18:19 ` Jonathan Wakely [this message]
2020-09-10 18:20 ` [committed 4/5] libstdc++: Fix -Wunused-local-typedefs warning Jonathan Wakely
2020-09-10 18:20 ` [committed 5/5] libstdc++: Fix -Wsign-compare warnings Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200910181917.GI6061@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).