From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 63ABC386100A for ; Thu, 24 Jun 2021 19:39:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 63ABC386100A Received: by mail-wr1-x42b.google.com with SMTP id b3so7930524wrm.6 for ; Thu, 24 Jun 2021 12:39:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jhpj5DTJn61n1xerDnWSPJrQZyLgEVjfQaTAhy0TNjo=; b=BvkACslg2iTxx9UsqqBIoTi3/RGOfsFEwnLRUForQ75xtFP1fWbgSbuH+W9dqzw54Z ZRJaEn4+QWjmxxmZwviKOIgatNj7Q1aOZWWGp8wewhr0ZiL7qpU1YkYQFJ9fO05uvd2O q5BVpxvV/ilnaTeDpW9SR29LgkQw5AEj8vjCnywRJIsP4X16pxS+1dbqPuhXVXyGBp/I JEtqbWlQQNuci2AmNhRbtiUU86u1o+8UKBgxk+8x34CLo4rXIekogLSXa98ByzF4SGDO fF2RerMPLBiPkleikXLTIVLomeTaorudGvXIAmU0U/WOGKVj6/fI6Kj1VoLnMxz8oBuQ 3Q9g== X-Gm-Message-State: AOAM530Fv7KZ9OJksElmfKcXGVWWWv/ytwLU9C3OyoOdfrUFzTS0k7hJ klDymuQuGGSIxKTc7y0R1DGy2xid3lVJC161WyE= X-Google-Smtp-Source: ABdhPJyZQYQCzjM5vh4Mg07oSKG2rpdAitKQqg45eLmj6DZ5UFAO6YAZg5AalWvVQCF9S+YX0uy453flM5fNhCxPZJI= X-Received: by 2002:a5d:6d8b:: with SMTP id l11mr6373590wrs.21.1624563573402; Thu, 24 Jun 2021 12:39:33 -0700 (PDT) MIME-Version: 1.0 References: <67864633-a933-98d5-4edc-eecdf50cbcf1@honermann.net> In-Reply-To: <67864633-a933-98d5-4edc-eecdf50cbcf1@honermann.net> From: Jonathan Wakely Date: Thu, 24 Jun 2021 20:39:22 +0100 Message-ID: Subject: Re: [PATCH] C++ P0482R6 char8_t: declare std::c8rtomb and std::mbrtoc8 if provided by the C library To: Tom Honermann Cc: Jonathan Wakely , "libstdc++@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jun 2021 19:39:36 -0000 On Thu, 24 Jun 2021 at 20:35, Tom Honermann via Libstdc++ wrote: > > On 6/23/21 1:27 PM, Jonathan Wakely wrote: > > N.B. please CC gcc-patches as well when sending patches to this list. > Ah, yes, I think you've reminded me of that before. > > > > On Mon, 7 Jun 2021 at 03:16, Tom Honermann via Libstdc++ > > wrote: > >> This patch completes implementation of the C++20 proposal P0482R6 [1] by > >> adding declarations of std::c8rtomb() and std::mbrtoc8() if provided by > >> the C library. > >> > >> Autoconf changes determine if the C library declares c8rtomb and mbrtoc8 > >> at global scope when uchar.h is included and compiled with -fchar8_t; > >> _GLIBCXX_USE_UCHAR_CHAR8_T is defined if so. The header > >> re-declares these functions in the std namespace only if available and > >> the C++20 __cpp_char8_t feature test macro is defined. > > > > Thanks, Tom. I'm surprised that there's no __cplusplus dependency > > here. Some C libraries aren't going to declare these new functions > > unconditionally, only for C2x and C++20 modes. Your new configure > > check tests for them with -std=c++11 -fchar8_t (and the implicit > > -D_GNU_SOURCE on GNU/Linux) which doesn't guarantee they'll be > > available. > > > > This isn't a problem for your glibc patches, because you do: > > > > +#if defined _CHAR8_T_SOURCE || defined __cpp_char8_t > > +# define __GLIBC_USE_CHAR8_T 1 > > > > But consider a hypothetical libc that only define the new functions > > for C2x/C++20, ignoring the __cpp_char8_t set by -fchar8_t. For such a > > libc the configure test using -std=c++11 -fchar8_t will fail, and > > libstdc++ won't declare the functions in namespace std even though > > they are in libc. > > > > Shouldn't the configure test use -std=c++20 instead to check that > > they're available for C++20 mode, and then in guard the using > > declarations for ::c8rtomb and ::mbrtoc8 with #if __cplusplus >= > > 202002L ? > > > > That would mean they're not declared in pre-C++20 when using > > -fchar8_t, but that seems a lesser problem than having them not > > declared in C++20 when they are actually present in libc. Maybe to > > solve that we need two configure macros (or one macro with multiple > > values), one that says the new functions are available for C++20, and > > another that says they are also available pre-C++20 if __cpp_char8_t > > is defined. Then can do something like: > > > > #if (__cplusplus >= 202002 && _GLIBCXX_USE_UCHAR_CXX20) \ > > || (__cpp_char8_t && _GLIBCXX_USE_UCHAR_CHAR8_T) > > > > Messy. Hmm. > > Yup, you hit all the points I struggled with when coming up with an > initial solution. In the end, I settled on use of the C++ feature test > macro being the only solution that worked in all cases, but it does > imply that C libraries consistently follow suit. We could just go with your patch for now, and see what happens when other C libraries start to add the new functions. But if you are willing to work on a revised patch with the extra conditions, that would be good. > Multiple probes seems like a reasonable option. I think it is fair to > assume that, if the declarations are present for -std=c++11 -fchar8_t, > then they will also be present for later language standards. So, if > that probe fails, we can then probe again using just -std=c++20. Sounds good. > The conditional above would encounter errors for -std=c++20 -fno-char8_t > for libc libraries that condition the declarations on the feature test > macro. I think it is reasonable to only enable the std namespace > declarations if the __cpp_char8_t feature test macro is defined. > > #if __cpp_char8_t \ > && (_GLIBCXX_USE_UCHAR_CXX11_CHAR8_T\ > || (__cplusplus >= 202002 &&_GLIBCXX_USE_UCHAR_CXX20)) > > Still messy, but I think this covers all the bases. I did consider the -fno-char8_t case and decided I didn't care for those people, but your suggestion allows it to work for them, without making it _too_ much messier.