public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Joseph Myers <joseph@codesourcery.com>
To: Tom Honermann <tom@honermann.net>
Cc: libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH 2/3]: C++20 P0482R6 and C2X N2653: Implement mbrtoc8, c8rtomb, char8_t
Date: Fri, 11 Jun 2021 16:28:58 +0000	[thread overview]
Message-ID: <alpine.DEB.2.22.394.2106111606170.479659@digraph.polyomino.org.uk> (raw)
In-Reply-To: <1c33efce-b4ed-a238-aa3a-7b15fa3dd495@honermann.net>

On Fri, 11 Jun 2021, Tom Honermann via Libc-alpha wrote:

> 1) Enabling pre-C2x compatibility with C++20.

Where a feature in a header should be enabled for a particular C++ 
version, we can have an internal __GLIBC_USE (CXX20) which is enabled 
based on the value of __cplusplus, just like the existing __USE_ISOCXX11.  
(Though that doesn't make much practical difference until we provide a way 
for C++ library headers to get all the features they need without defining 
_GNU_SOURCE.)

You'd then have

#if defined __USE_GNU || __GLIBC_USE (CXX20)

in uchar.h, with appropriate !defined __cpp_char8_t for defining the 
typedef itself.  And the defined __USE_GNU would become __GLIBC_USE 
(ISOC2X) if the feature is accepted for C2x.

> 2) Enabling conditional code sensitive to the change of type of u8 string
> literals.

That might be a reason for a compiler option (I don't think it's a 
sufficient reason, I expect -std=c11 or -Wno-pointer-sign or pointer casts 
to suffice in practice), but it has nothing to do with the use of feature 
test macros in glibc since the library headers don't care at all what the 
type of u8 string literals is (there are no u8 string literals anywhere in 
glibc).

> 3) Avoiding clashes with existing uses of the char8_t identifier in code that
> may be compiled with _GNU_SOURCE.

It's a universal feature in glibc that all non-obsolescent, 
non-conflicting features are enabled with _GNU_SOURCE, including features 
from future standard versions - all feature test macros are subsets of 
_GNU_SOURCE, except where the features actually conflict in some way (a 
few cases where a POSIX function has semantics incompatible with a GNU 
function of the same name), and features from future standards with no 
feature test macro support in glibc (e.g. some features proposed for the 
next POSIX version) are also enabled by _GNU_SOURCE.

So char8_t and these functions should be enabled by _GNU_SOURCE, 
regardless of what other options enable them.

Users of _GNU_SOURCE are expected to deal with possible naming conflicts 
with features added to _GNU_SOURCE.  Likewise people building with 
-std=gnu2x / -std=c2x, which would enable these declarations if char8_t 
and these functions are added to C2x, or users of _ISOC2X_SOURCE (which 
isn't expected to be used much).

> I agree that this is a narrow feature, but I think the feature test macro is
> beneficial for compatibility reasons.  Assuming the proposal is adopted for
> C23, some programmers may need to opt-out of the feature by compiling with
> -fno-char8_t during a migration period; as some C++20 projects have done.

We don't provide a way to opt out of any other library additions when 
compiling in C2x mode; compiling with -std=c2x or -std=gnu2x or 
-D_GNU_SOURCE unconditionally enables all other C2x additions in headers 
(including e.g. the iszero macro, although the issues seen with that were 
mainly for C++ code and we addressed that by making it a template instead 
of a macro for C++), compiling with e.g. -std=c11 or -std=gnu11 (and not 
using _GNU_SOURCE) is how you opt out of all such additions at the same 
time.  Likewise for previous C standard versions.  And _GNU_SOURCE is the 
universal way to opt in to features that might or might not be in a future 
standard version.  If such a feature has its own TS, we may support the 
__STDC_WANT_* macros from such a TS, but that's not a basis for creating 
our own feature test macro for a handful of new identifiers.

-- 
Joseph S. Myers
joseph@codesourcery.com

  reply	other threads:[~2021-06-11 16:29 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-07  2:08 Tom Honermann
2021-06-07 18:53 ` Joseph Myers
2021-06-11 11:25   ` Tom Honermann
2021-06-11 16:28     ` Joseph Myers [this message]
2021-06-13 15:35       ` Tom Honermann
2022-01-08  0:39 Tom Honermann
2022-01-11  0:53 ` Joseph Myers
2022-01-11 19:23   ` Tom Honermann
2022-01-20 23:17     ` Tom Honermann
2022-01-21 20:01       ` Adhemerval Zanella
2022-01-22 12:24         ` Tom Honermann
2022-02-16 18:29           ` Joseph Myers
2022-02-16 19:14             ` tom
2022-02-27 16:53 Tom Honermann
2022-02-28 23:01 ` Joseph Myers
2022-03-01  3:40   ` Tom Honermann
2022-05-17 15:57     ` Carlos O'Donell
2022-05-17 18:05     ` Adhemerval Zanella
2022-05-17 18:12       ` Joseph Myers
2022-05-17 18:17         ` Adhemerval Zanella
2022-05-17 21:33           ` Florian Weimer
2022-05-18 15:32             ` Tom Honermann
2022-05-18 16:17               ` Adhemerval Zanella
2022-05-18 17:26                 ` Tom Honermann
2022-05-18 17:39                   ` Adhemerval Zanella
2022-05-18 17:40                 ` Florian Weimer
2022-05-18 17:57                   ` Adhemerval Zanella

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=alpine.DEB.2.22.394.2106111606170.479659@digraph.polyomino.org.uk \
    --to=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=tom@honermann.net \
    /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).