From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1105) id AB788385840A; Wed, 7 Sep 2022 18:39:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB788385840A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1662575990; bh=nYN5uz9IsSECumpTATWB5jDYhIwUdvDv7iMJOGV2lcA=; h=From:To:Subject:Date:From; b=uuiSwiVfbaETA95Sjm5BkDTndb63XniPSpgoaW9J3M7qAWZA62s4Q89H/1Y1/7gcx lANtwWO2f+j0EtVQh1gf2mnGLpelrnYQS4t9fstZpu4ZCE6BOyifm0x1kFyyeK5JcC 9bXsldZ5/zy3LUobvBrv0FDOfYV/8MQ73kP93qUA= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Joseph Myers To: glibc-cvs@sourceware.org Subject: [glibc] Do not define static_assert or thread_local in headers for C2x X-Act-Checkin: glibc X-Git-Author: Joseph Myers X-Git-Refname: refs/heads/master X-Git-Oldrev: 89d40cacd0aed35e2546513ce01924b879523e46 X-Git-Newrev: b8cc607f3c1e8371b89158f427a61f28018604a5 Message-Id: <20220907183950.AB788385840A@sourceware.org> Date: Wed, 7 Sep 2022 18:39:50 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b8cc607f3c1e8371b89158f427a61f28018604a5 commit b8cc607f3c1e8371b89158f427a61f28018604a5 Author: Joseph Myers Date: Wed Sep 7 18:39:28 2022 +0000 Do not define static_assert or thread_local in headers for C2x C2x makes static_assert and thread_local into keywords, removing the definitions as macros in assert.h and threads.h. Thus, disable those macros in those glibc headers for C2x. The disabling is done based on a combination of language version and __GNUC_PREREQ, *not* based on __GLIBC_USE (ISOC2X), on the principle that users of the header (when requesting C11 or later APIs - not assert.h for C99 and older API versions) should always have the names static_assert or thread_local available after inclusion of the header, whether as a keyword or as a macro. Thus, when using a compiler without the keywords (whether an older compiler, possibly in C2x mode, or _GNU_SOURCE with any compiler but in an older language mode, for example) the macros should be defined, even when C2x APIs have been requested. The __GNUC_PREREQ conditionals here may well need updating with the versions of other compilers that gained support for these keywords in C2x mode. Tested for x86_64. Diff: --- assert/assert.h | 6 +++++- sysdeps/pthread/threads.h | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/assert/assert.h b/assert/assert.h index 67f1cce5e9..b438d8eeb7 100644 --- a/assert/assert.h +++ b/assert/assert.h @@ -135,7 +135,11 @@ __END_DECLS #endif /* NDEBUG. */ -#if defined __USE_ISOC11 && !defined __cplusplus +#if (defined __USE_ISOC11 \ + && (!defined __STDC_VERSION__ \ + || __STDC_VERSION__ <= 201710L \ + || !__GNUC_PREREQ (13, 0)) \ + && !defined __cplusplus) # undef static_assert # define static_assert _Static_assert #endif diff --git a/sysdeps/pthread/threads.h b/sysdeps/pthread/threads.h index 687b45c610..13c8f35768 100644 --- a/sysdeps/pthread/threads.h +++ b/sysdeps/pthread/threads.h @@ -27,7 +27,9 @@ __BEGIN_DECLS #include #include -#ifndef __cplusplus +#if (!defined __STDC_VERSION__ \ + || __STDC_VERSION__ <= 201710L \ + || !__GNUC_PREREQ (13, 0)) && !defined __cplusplus # define thread_local _Thread_local #endif