From patchwork Tue Oct 5 08:35:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 45822 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3E5B3858436 for ; Tue, 5 Oct 2021 08:48:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3E5B3858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633423738; bh=5NnYsfiUnjz/D5nNH+bTaQlqS/SEk/a73BthpZ3cVIY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=TUkQ6KIPf/JzclF0vuggZpfmOsiqePTCT3VOp5C04wZfUb9vCFt0CewJ+11Cr3ohz apAYM9tY+00qcIQl4s55xc+cNKlGKk8CATGnGwxrG2MiuISzO9sV9eURFVXsXeVS4i ozWSE4H6bFfDehEMpsXJjiaMhJS7oGYOONO40yHo= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 5B060385AC1A for ; Tue, 5 Oct 2021 08:35:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5B060385AC1A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-373-2LBCt9dhNE-UnCWlRn1-GQ-1; Tue, 05 Oct 2021 04:35:21 -0400 X-MC-Unique: 2LBCt9dhNE-UnCWlRn1-GQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4488818125C4; Tue, 5 Oct 2021 08:35:20 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.109]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A66475F4ED; Tue, 5 Oct 2021 08:35:16 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 1958ZD1T1726262 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 5 Oct 2021 10:35:14 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 1958ZCG51726261; Tue, 5 Oct 2021 10:35:12 +0200 Date: Tue, 5 Oct 2021 10:35:12 +0200 To: Jason Merrill , "Joseph S. Myers" , Marek Polacek Subject: [PATCH] c++: Implement C++23 P2334R1 - #elifdef/#elifndef Message-ID: <20211005083512.GT304296@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! This patch implements C++23 P2334R1, which is easy because Joseph has done all the hard work for C2X already. Unlike the C N2645 paper, the C++ P2334R1 contains one important addition (but not in the normative text): "While this is a new preprocessor feature and cannot be treated as a defect report, implementations that support older versions of the standard are encouraged to implement this feature in the older language modes as well as C++23." so there are different variants how to implement it. One is in the patch below, ignores that sentence and only implements it for -std=c++23/-std=gnu++23 like it is only implemented for -std=c23. Another option would be to implement it also in the older GNU modes but not in the C/CXX modes (but it would be strange if we did that just for C++ and not for C). Yet another option is to enable it unconditionally. And yet another option would be to enable it unconditionally but emit a warning (or pedwarn) when it is seen. Note, when it is enabled for the older language modes, as Joseph wrote in the c11-elifdef-1.c testcase, it can result e.g. in rejecting previously valid code: #define A #undef B #if 0 #elifdef A #error "#elifdef A applied" #endif #if 0 #elifndef B #error "#elifndef B applied" #endif Note, seems clang went the enable it unconditionally in all standard versions of both C and C++, no warnings or anything whatsoever, so essentially treated it as a DR that changed behavior of e.g. the above code. 2021-10-05 Jakub Jelinek libcpp/ * init.c (lang_defaults): Implement P2334R1, enable elifdef for -std=c++23 and -std=gnu++23. gcc/testsuite/ * g++.dg/cpp/elifdef-1.C: New test. * g++.dg/cpp/elifdef-2.C: New test. * g++.dg/cpp/elifdef-3.C: New test. Jakub --- libcpp/init.c.jj 2021-09-02 10:01:15.954715595 +0200 +++ libcpp/init.c 2021-10-05 09:55:15.010620700 +0200 @@ -122,8 +122,8 @@ static const struct lang_flags lang_defa /* CXX17 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0 }, /* GNUCXX20 */ { 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0 }, /* CXX20 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0 }, - /* GNUCXX23 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0 }, - /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0 }, + /* GNUCXX23 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1 }, + /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1 }, /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; --- gcc/testsuite/g++.dg/cpp/elifdef-1.C.jj 2021-10-05 10:00:41.410057024 +0200 +++ gcc/testsuite/g++.dg/cpp/elifdef-1.C 2021-10-05 10:00:33.110173069 +0200 @@ -0,0 +1,3 @@ +// { dg-do preprocess { target { ! c++23 } } } + +#include "../../gcc.dg/cpp/c11-elifdef-1.c" --- gcc/testsuite/g++.dg/cpp/elifdef-2.C.jj 2021-10-05 10:01:30.345372808 +0200 +++ gcc/testsuite/g++.dg/cpp/elifdef-2.C 2021-10-05 10:03:36.560608083 +0200 @@ -0,0 +1,4 @@ +// P2334R1 +// { dg-do preprocess { target c++23 } } + +#include "../../gcc.dg/cpp/c2x-elifdef-1.c" --- gcc/testsuite/g++.dg/cpp/elifdef-3.C.jj 2021-10-05 10:01:36.029293338 +0200 +++ gcc/testsuite/g++.dg/cpp/elifdef-3.C 2021-10-05 10:03:48.896435601 +0200 @@ -0,0 +1,4 @@ +// P2334R1 +// { dg-do preprocess { target c++23 } } + +#include "../../gcc.dg/cpp/c2x-elifdef-1.c"