From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 7EFBF3858428 for ; Wed, 7 Sep 2022 15:15:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7EFBF3858428 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.93,297,1654588800"; d="scan'208";a="82477874" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 07 Sep 2022 07:15:32 -0800 IronPort-SDR: 0UtdupBKJQPOeGKhhOSkrXQmZup0Mn3nmlUytVdJJHz8tThBM9ravenXqOE+W6P0/e0IFiAT+6 aU2xK38N5TV23S5i/fjZr24nyFR9g13hv3hEg5A9fwSQkL/P5QJD1V771F2g5CepxKhr6ZaGrN /eYc29SbvWkdJLx44LL/Y/9K3/z4eclZ6JoUPUt25E8vXHB4CZutCGeEJlYyLsZmItM1cDPIro MoBXxq3Ni35DkoOGuWu5fCE0uEUzvsFpso5Sqz1C+n3Xk9SNXe+WfStBH7QrqGdkKmogsvnshY ZoA= Date: Wed, 7 Sep 2022 15:15:26 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: Do not define static_assert or thread_local in headers for C2x Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-07.mgc.mentorg.com (139.181.222.7) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-3117.3 required=5.0 tests=BAYES_00,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 --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 -- Joseph S. Myers joseph@codesourcery.com