From patchwork Wed Oct 23 14:39:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 2001146 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YsKyq9sk; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XYWtw5ncnz1xtp for ; Thu, 24 Oct 2024 01:40:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 02AFF3858423 for ; Wed, 23 Oct 2024 14:40:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id B093F3858D33 for ; Wed, 23 Oct 2024 14:40:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B093F3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B093F3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729694422; cv=none; b=GmTWN6MsG0MkV0sPHf9WPnRAweOJDQDgSNhNO2RFV0Atz24NCOmJOKdgBHsOMNmwdZIV7b8r/nE4sSC6QMCKm69tzcJ4lNffDnX4OC3VdLQ8iU3vzS7/go2/3CM4/xI/KmTV2bWL/yPi+EH9awIY4CgoeozS0oYAP+nZrrRRU40= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729694422; c=relaxed/simple; bh=hS6oBu7kOTO6/+P3eBHnZ4cBJo8PEbHXKUC0x0yzYiA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qyPnzPGZVF6eoUKSjS57E6QySU9vivb+3tE96mHzA6sfy3sqIW5WQpFJHN/uTiwKWzSNu4+Kvvz5mVDOrtcl0o53Vfer6knRxkTJCHekPufrTK1/9UyXzfWTcVpFXKYepvxF1iTtq2VekDxPOkYg9t/sBMR8n8eXB9HTdTv6Vxc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729694405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bFZmbzSXuKR4o3WvmOMnelMjq1vWbSEHeNV591ACCCE=; b=YsKyq9skFw1jeo01up85miQXbMEooeRCETwtWAU6GVsjsN2QOyYtg2dMmJhPMNF118zlDA 0JwxJGAg7d3ldh6jW0BSXU25eLPouCy04Pka/0oUPC3kCiCubQEjXzIes5WfIT38ekxuzF RX9BEo3tNtFkdnu18L8FF2DoxixR2r0= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-54-qzuJcix6PD2l1uBw5wxKwQ-1; Wed, 23 Oct 2024 10:40:02 -0400 X-MC-Unique: qzuJcix6PD2l1uBw5wxKwQ-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6D22B19560AF; Wed, 23 Oct 2024 14:40:01 +0000 (UTC) Received: from localhost (unknown [10.42.28.5]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D38971956056; Wed, 23 Oct 2024 14:40:00 +0000 (UTC) From: Jonathan Wakely To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Joseph Myers , Jason Merrill Subject: [PATCH] ginclude: stdalign.h should define __xxx_is_defined macros for C++ Date: Wed, 23 Oct 2024 15:39:16 +0100 Message-ID: <20241023143959.1195051-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org The __alignas_is_defined macro has been required by C++ since C++11, and C++ Library DR 4036 clarified that __alignof_is_defined should be defined too. The macros alignas and alignof should not be defined, as they're keywords in C++. Technically it's implementation-defined whether __STDC_VERSION__ is defined by a C++ compiler, but G++ does not define it. Adjusting the first #if this way works as intended: A C23 compiler will not enter the outer if-group and so will not define any of the macros, a C17 compiler will enter both if-groups and so define all the macros, and a C++ compiler will enter the outer if-group but not the inner if-group. gcc/ChangeLog: * ginclude/stdalign.h (__alignas_is_defined): Define for C++. (__alignof_is_defined): Likewise. libstdc++-v3/ChangeLog: * testsuite/18_support/headers/cstdalign/macros.cc: New test. --- The libc++ devs noticed recently that GCC's doesn't conform to the C++ requirements. Tested x86_64-linux. OK for trunk? gcc/ginclude/stdalign.h | 5 ++-- .../18_support/headers/cstdalign/macros.cc | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/18_support/headers/cstdalign/macros.cc diff --git a/gcc/ginclude/stdalign.h b/gcc/ginclude/stdalign.h index 5f82f2d68f2..af73c322624 100644 --- a/gcc/ginclude/stdalign.h +++ b/gcc/ginclude/stdalign.h @@ -26,11 +26,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #ifndef _STDALIGN_H #define _STDALIGN_H -#if (!defined __cplusplus \ - && !(defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L)) +#if !(defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L) +#ifndef __cplusplus #define alignas _Alignas #define alignof _Alignof +#endif #define __alignas_is_defined 1 #define __alignof_is_defined 1 diff --git a/libstdc++-v3/testsuite/18_support/headers/cstdalign/macros.cc b/libstdc++-v3/testsuite/18_support/headers/cstdalign/macros.cc new file mode 100644 index 00000000000..c50c921cd59 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/headers/cstdalign/macros.cc @@ -0,0 +1,24 @@ +// { dg-options "-D_GLIBCXX_USE_DEPRECATED=1 -Wno-deprecated" } +// { dg-do preprocess { target c++11 } } + +#include + +#ifndef __alignas_is_defined +# error "The header fails to define a macro named __alignas_is_defined" +#elif __alignas_is_defined != 1 +# error "__alignas_is_defined is not defined to 1 in " +#endif + +#ifndef __alignof_is_defined +# error "The header fails to define a macro named __alignof_is_defined" +#elif __alignof_is_defined != 1 +# error "__alignof_is_defined is not defined to 1 in " +#endif + +#ifdef alignas +# error "The header defines a macro named alignas" +#endif + +#ifdef alignof +# error "The header defines a macro named alignof" +#endif