From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id F32053858D20 for ; Tue, 14 Nov 2023 22:01:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F32053858D20 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 F32053858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699999289; cv=none; b=O2HYJyBRQ3snytyhXEkveIuOwfxgbsM9jveRQLvPpiNeXYdNNSPf9y/0p8mG279Q243C84LTgmkaexv7UmlF2v9Ar+HoICyFu5ImncGyHUJntezUsz/jSZrSibwvB9aBYuSE0cYXnldqJCFRk6FskMZk0DurOuCbRr4ojlYqdTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699999289; c=relaxed/simple; bh=BOFb7F9BUVXGbBiOdLIjhn8gfdU5Mk5YuOkFoVrtHFc=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=B7qBeZHBseuuV7XeMkGP9BcIciKTHkw4NA7qR3TOCAQDCIomuxe+Tn5QXS6GbpVjtumWzCMOzY1Q2DeZFAxFz+ZWGIuLCIvhucmc8PIePFq8dhUtdWcMqdxiYEwaTVESAtw2I6J1TZd4UTnLo08uukeMF+NEQWMNzsaRcZ1xH28= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699999287; 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: in-reply-to:in-reply-to:references:references; bh=QmQPyb7ybcu1RTAxgHGNB0OConzBEpg6wVm/AKf5+UE=; b=AQu/rrKYwxLrmOabcYhTA3sHgP846nU9gt3/IYQ63pMVvp5AVSfz08zDLdgvraLuKHbfxu rCLLjCLC48kXZq0eRMhevFsLPiy78wnCLDyV8m0j46VqaTLJ/kXkm+bJuos8IaObDdX5g2 MLx5r0NHNM6cbu4lA3ao2qaZUUP6yAM= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-T9wu3KCnPweqk5TyK6Dkxw-1; Tue, 14 Nov 2023 17:01:26 -0500 X-MC-Unique: T9wu3KCnPweqk5TyK6Dkxw-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-41cdc2cc0b4so4484601cf.0 for ; Tue, 14 Nov 2023 14:01:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699999285; x=1700604085; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QmQPyb7ybcu1RTAxgHGNB0OConzBEpg6wVm/AKf5+UE=; b=X6QFtiz7aRgu56lvuXhdJdVWDatQ+mHFI4NdBktB1tedtvs7LDT6+a21TK/SMLUF0g Y4UUHkrbpk/W9ITVsy1uJC6RS47LhErQtqzR+6oZN3m4dFV5PAtCG1d8QN8vmf4bsxgJ jLGAfQbLV8lJuru0f5HJeXYpALUBuSY9bZPFMhgy/AXbowpMPrix1MPLf/FsuiVp4owF 2qFR203bUA0QuiaN1hIf3bB8MdYv9yd9Nh+vWIeM8bBL54rsgL5H2BA4nasaxdRUf7jO 33KzMVya0hBtw35pkqysFmAqe9aQWJWkAaxFolXSbRkfPtzQiFWkh2jsNFTnHEGKKTdD vy0Q== X-Gm-Message-State: AOJu0YwryfWxx1qOdAmHAgO8ejFPh2v2EGp2eUO013X8/6SEPwKA8Mtd TTpeIMMzRz4q6dkkD0QvDuvDQI3SI7FUIee8rzhWPvGYxfkEB+mIMEoYKrHrhu5LSbupOmViybf vRu9Fuw7UCmhK+EFi0Q== X-Received: by 2002:a05:622a:4ce:b0:41c:c68c:1df2 with SMTP id q14-20020a05622a04ce00b0041cc68c1df2mr5297503qtx.5.1699999285414; Tue, 14 Nov 2023 14:01:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEebqjoT+n8JNOpNEeXyYGLId0UpMxYoZinaZYHtZjOjeW54czULoqKeEk6MW0N38pbsYeanA== X-Received: by 2002:a05:622a:4ce:b0:41c:c68c:1df2 with SMTP id q14-20020a05622a04ce00b0041cc68c1df2mr5297465qtx.5.1699999285028; Tue, 14 Nov 2023 14:01:25 -0800 (PST) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id fu23-20020a05622a5d9700b00421ae93b7a5sm3036311qtb.2.2023.11.14.14.01.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Nov 2023 14:01:24 -0800 (PST) Message-ID: <148e6515-c2b2-4dc8-bc9a-f388a478c6ac@redhat.com> Date: Tue, 14 Nov 2023 17:01:18 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++, v2: Implement C++26 P2864R2 - Remove Deprecated Arithmetic Conversion on Enumerations From C++26 To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org, Marek Polacek References: <1c62f30c-8e9f-43a1-a667-6f3a0cd95230@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 11/14/23 12:38, Jakub Jelinek wrote: > On Mon, Nov 13, 2023 at 10:59:52PM -0500, Jason Merrill wrote: >> On 11/13/23 06:50, Jakub Jelinek wrote: >>> The following patch implements C++26 P2864R2 by emitting pedwarn enabled by >>> the same options as the C++20 and later warnings (i.e. -Wenum-compare, >>> -Wdeprecated-enum-enum-conversion and -Wdeprecated-enum-float-conversion >>> which are all enabled by default). I think we still want to allow users >>> some option workaround, so am not using directly error, but if that is >>> what you want instead, I can change it. >> >> I agree, but we also need to return error_mark_node for these cases when >> SFINAE, i.e. !(complain & tf_warning_or_error) > > So like this then? > > Bootstrapped/regtested on x86_64-linux and i686-linux. > > 2023-11-14 Jakub Jelinek > > gcc/cp/ > * typeck.cc: Implement C++26 P2864R2 - Remove Deprecated Arithmetic > Conversion on Enumerations From C++26. > (do_warn_enum_conversions): Return bool rather than void, add COMPLAIN > argument. Use pedwarn rather than warning_at for C++26 and remove > " is deprecated" part of the diagnostics in that case. For SFINAE > in C++26 return true on newly erroneous cases. > (cp_build_binary_op): For C++26 call do_warn_enum_conversions > unconditionally, pass complain argument to it and if it returns true, > return error_mark_node. > * call.cc (build_conditional_expr): Use pedwarn rather than warning_at > for C++26 and remove " is deprecated" part of the diagnostics in that > case and check for complain & tf_warning_or_error. Use emit_diagnostic > with cxx_dialect >= cxx26 ? DK_PEDWARN : DK_WARNING. For SFINAE in > C++26 return error_mark_node on newly erroneous cases. > (build_new_op): Use emit_diagnostic with cxx_dialect >= cxx26 > ? DK_PEDWARN : DK_WARNING and complain & tf_warning_or_error check > for C++26. For SFINAE in C++26 return error_mark_node on newly > erroneous cases. > gcc/testsuite/ > * g++.dg/cpp26/enum-conv1.C: New test. > * g++.dg/cpp2a/enum-conv1.C: Adjust expected diagnostics in C++26. > * g++.dg/diagnostic/enum3.C: Likewise. > * g++.dg/parse/attr3.C: Likewise. > * g++.dg/cpp0x/linkage2.C: Likewise. > > --- gcc/cp/typeck.cc.jj 2023-11-13 13:02:21.573785549 +0100 > +++ gcc/cp/typeck.cc 2023-11-14 09:49:31.026997048 +0100 > @@ -4940,16 +4940,25 @@ warn_for_null_address (location_t locati > type, this behavior is deprecated ([depr.arith.conv.enum]). CODE is the > code of the binary operation, TYPE0 and TYPE1 are the types of the operands, > and LOC is the location for the whole binary expression. > + For C++26 this is ill-formed rather than deprecated. > + Return true for SFINAE errors. > TODO: Consider combining this with -Wenum-compare in build_new_op_1. */ > > -static void > +static bool > do_warn_enum_conversions (location_t loc, enum tree_code code, tree type0, > - tree type1) > + tree type1, tsubst_flags_t complain) > { > if (TREE_CODE (type0) == ENUMERAL_TYPE > && TREE_CODE (type1) == ENUMERAL_TYPE > && TYPE_MAIN_VARIANT (type0) != TYPE_MAIN_VARIANT (type1)) > { > + if (cxx_dialect >= cxx26) > + { > + if ((complain & tf_warning_or_error) == 0) > + return true; > + } > + else if ((complain & tf_warning) == 0) > + return false; > /* In C++20, -Wdeprecated-enum-enum-conversion is on by default. > Otherwise, warn if -Wenum-conversion is on. */ > enum opt_code opt; > @@ -4958,7 +4967,7 @@ do_warn_enum_conversions (location_t loc > else if (warn_enum_conversion) > opt = OPT_Wenum_conversion; > else > - return; > + return false; > > switch (code) > { > @@ -4969,21 +4978,29 @@ do_warn_enum_conversions (location_t loc > case EQ_EXPR: > case NE_EXPR: > /* Comparisons are handled by -Wenum-compare. */ > - return; > + return false; > case SPACESHIP_EXPR: > /* This is invalid, don't warn. */ > - return; > + return false; > case BIT_AND_EXPR: > case BIT_IOR_EXPR: > case BIT_XOR_EXPR: > - warning_at (loc, opt, "bitwise operation between different " > - "enumeration types %qT and %qT is deprecated", > - type0, type1); > - return; > + if (cxx_dialect >= cxx26) > + pedwarn (loc, opt, "bitwise operation between different " > + "enumeration types %qT and %qT", type0, type1); > + else > + warning_at (loc, opt, "bitwise operation between different " > + "enumeration types %qT and %qT is deprecated", > + type0, type1); > + return false; > default: > - warning_at (loc, opt, "arithmetic between different enumeration " > - "types %qT and %qT is deprecated", type0, type1); > - return; > + if (cxx_dialect >= cxx26) > + pedwarn (loc, opt, "arithmetic between different enumeration " > + "types %qT and %qT", type0, type1); > + else > + warning_at (loc, opt, "arithmetic between different enumeration " > + "types %qT and %qT is deprecated", type0, type1); > + return false; > } > } > else if ((TREE_CODE (type0) == ENUMERAL_TYPE > @@ -4991,6 +5008,13 @@ do_warn_enum_conversions (location_t loc > || (SCALAR_FLOAT_TYPE_P (type0) > && TREE_CODE (type1) == ENUMERAL_TYPE)) > { > + if (cxx_dialect >= cxx26) > + { > + if ((complain & tf_warning_or_error) == 0) > + return true; > + } > + else if ((complain & tf_warning) == 0) > + return false; > const bool enum_first_p = TREE_CODE (type0) == ENUMERAL_TYPE; > /* In C++20, -Wdeprecated-enum-float-conversion is on by default. > Otherwise, warn if -Wenum-conversion is on. */ > @@ -5000,7 +5024,7 @@ do_warn_enum_conversions (location_t loc > else if (warn_enum_conversion) > opt = OPT_Wenum_conversion; > else > - return; > + return false; > > switch (code) > { > @@ -5010,7 +5034,13 @@ do_warn_enum_conversions (location_t loc > case LE_EXPR: > case EQ_EXPR: > case NE_EXPR: > - if (enum_first_p) > + if (enum_first_p && cxx_dialect >= cxx26) > + pedwarn (loc, opt, "comparison of enumeration type %qT with " > + "floating-point type %qT", type0, type1); > + else if (cxx_dialect >= cxx26) > + pedwarn (loc, opt, "comparison of floating-point type %qT " > + "with enumeration type %qT", type0, type1); > + else if (enum_first_p) > warning_at (loc, opt, "comparison of enumeration type %qT with " > "floating-point type %qT is deprecated", > type0, type1); > @@ -5018,12 +5048,18 @@ do_warn_enum_conversions (location_t loc > warning_at (loc, opt, "comparison of floating-point type %qT " > "with enumeration type %qT is deprecated", > type0, type1); > - return; > + return false; > case SPACESHIP_EXPR: > /* This is invalid, don't warn. */ > - return; > + return false; > default: > - if (enum_first_p) > + if (enum_first_p && cxx_dialect >= cxx26) > + pedwarn (loc, opt, "arithmetic between enumeration type %qT " > + "and floating-point type %qT", type0, type1); > + else if (cxx_dialect >= cxx26) > + pedwarn (loc, opt, "arithmetic between floating-point type %qT " > + "and enumeration type %qT", type0, type1); > + else if (enum_first_p) > warning_at (loc, opt, "arithmetic between enumeration type %qT " > "and floating-point type %qT is deprecated", > type0, type1); > @@ -5031,9 +5067,10 @@ do_warn_enum_conversions (location_t loc > warning_at (loc, opt, "arithmetic between floating-point type %qT " > "and enumeration type %qT is deprecated", > type0, type1); > - return; > + return true; Shouldn't this be return false? OK with that change. Jason