From patchwork Fri Nov 11 07:43:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 18524 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp599457wru; Thu, 10 Nov 2022 23:43:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf4wO7gC0+RoyRDbAb82m07G7XQIY7KfbYCQu8mJz/ujxHRX0oNB9M910PDS+afVkRKHde8v X-Received: by 2002:a17:906:2315:b0:7ae:4a7f:3281 with SMTP id l21-20020a170906231500b007ae4a7f3281mr932644eja.50.1668152636692; Thu, 10 Nov 2022 23:43:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668152636; cv=none; d=google.com; s=arc-20160816; b=nhkFCphmvztykwoDbB3NbEiz6KzvnsYQ62mm+1gKr0hqticjb3YCi/ZWRDrOddpGMf 7e5XWKFp00LkgBOIfCw8romwfCYj578TQIP8sz8hhkYRthd9njAIBHERfaSyeWJzLxGQ BwFVopQsfskRJ3QTV9vIMifs+3Znl0zVJuzVZJJFqN8YtcEnoJN7lS5GXjqieusAI/UA RRCQ9jc8z7GGKlbXeNcpTU5Fc3B6a96pf8EXbyO3k3aqAMTpWDVJPMI+FjdSPlF/1xG4 ktbJK+Ed+VY9veVQGmH6qXCyOZ3cpIfLHJOaINy8htAKB9CuidulnWcJXC6dBC1lmeD6 mWwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=m79dWaLafBrNQRYgb9irlXlQzFANYFR+KAfAnJPAiKo=; b=l7O0jjCd0Bt8tR3c2XL+U3t6WOQpIyYceJAF0rSFeWeHkE0zg7PhxtKUQRHrkZO+sQ a4Ha810WwsWsgdp8/aNqz09MxFIunKb04sIxx13q6H0RTLghqbXCyor0gd/qXgS1I4U2 R4lMoK9gCfwvxmaBp/6K6VKKO5W5BnvPajpQRzhDaBBn4QtB70f49WUBB/DWTBff5grZ AP113lg6We3cOzZOaRovjcdmgGFqA90qxz3QkvnTK9wPSEbhe8KqcGhbtWxIYOwUSU+/ qxTsuL9V+IUrQX4Emr+/sIdhpHjWTj1t1BpyFiE/aLFxaSsWs6M3J939akb5Op7Hu3fv 9Vjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Sd8YJzvh; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w22-20020a056402269600b0045b265a1712si1872462edd.595.2022.11.10.23.43.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 23:43:56 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Sd8YJzvh; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 76DD43858C00 for ; Fri, 11 Nov 2022 07:43:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76DD43858C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668152635; bh=m79dWaLafBrNQRYgb9irlXlQzFANYFR+KAfAnJPAiKo=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Sd8YJzvh16rDIWreeyMHHTgt8kjENRJJhBMNNLW584iHDcROl8qgWyYsoOIU4/54Q PtV3T+4Nz0RfMx3VGvJ25kx+w78ydXd0VLTCR84mgItSUNCxkbfnnS1NIhtQaVA8NB 4kGoZwIoR0/PcttwzOQTFKileBFAd+yS86NXDpJA= 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 ESMTPS id 973D83858C5E for ; Fri, 11 Nov 2022 07:43:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 973D83858C5E Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-156-3UMWzAOZMqy9hz3KbKMcxA-1; Fri, 11 Nov 2022 02:43:06 -0500 X-MC-Unique: 3UMWzAOZMqy9hz3KbKMcxA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A7C448027EB for ; Fri, 11 Nov 2022 07:43:06 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 69CB740C83C5; Fri, 11 Nov 2022 07:43:06 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2AB7h4jq3247628 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 11 Nov 2022 08:43:04 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2AB7h3Cf3247627; Fri, 11 Nov 2022 08:43:03 +0100 Date: Fri, 11 Nov 2022 08:43:03 +0100 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Implement CWG 2654 - Un-deprecation of compound volatile assignments Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham 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.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 Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749184819181544235?= X-GMAIL-MSGID: =?utf-8?q?1749184819181544235?= Hi! Again, because stage1 close is near, posting the following patch to implement CWG 2654. Ok for trunk if it passes bootstrap/regtest and is voted into C++23 and C++20 as a DR? 2022-11-11 Jakub Jelinek * typeck.cc (cp_build_modify_expr): Implement CWG 2654 - Un-deprecation of compound volatile assignments. Remove -Wvolatile warning about compound volatile assignments. * g++.dg/cpp2a/volatile1.C (fn2, fn3, racoon): Adjust expected diagnostics. * g++.dg/cpp2a/volatile3.C (fn2, fn3, racoon): Likewise. * g++.dg/cpp2a/volatile5.C (f): Likewise. Jakub --- gcc/cp/typeck.cc.jj 2022-11-09 11:22:42.617628059 +0100 +++ gcc/cp/typeck.cc 2022-11-10 23:19:00.394228067 +0100 @@ -9513,19 +9513,6 @@ cp_build_modify_expr (location_t loc, tr && MAYBE_CLASS_TYPE_P (TREE_TYPE (lhstype))) || MAYBE_CLASS_TYPE_P (lhstype))); - /* An expression of the form E1 op= E2. [expr.ass] says: - "Such expressions are deprecated if E1 has volatile-qualified - type and op is not one of the bitwise operators |, &, ^." - We warn here rather than in cp_genericize_r because - for compound assignments we are supposed to warn even if the - assignment is a discarded-value expression. */ - if (modifycode != BIT_AND_EXPR - && modifycode != BIT_IOR_EXPR - && modifycode != BIT_XOR_EXPR - && (TREE_THIS_VOLATILE (lhs) || CP_TYPE_VOLATILE_P (lhstype))) - warning_at (loc, OPT_Wvolatile, - "compound assignment with %-qualified left " - "operand is deprecated"); /* Preevaluate the RHS to make sure its evaluation is complete before the lvalue-to-rvalue conversion of the LHS: --- gcc/testsuite/g++.dg/cpp2a/volatile1.C.jj 2022-08-16 13:15:22.739043862 +0200 +++ gcc/testsuite/g++.dg/cpp2a/volatile1.C 2022-11-10 23:23:18.949717772 +0100 @@ -74,17 +74,17 @@ fn2 () decltype(i = vi = 42) x3 = i; // Compound assignments. - vi += i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } - vi -= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } - vi %= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } + vi += i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } + vi -= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } + vi %= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } vi ^= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } vi |= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } vi &= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } - vi /= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } + vi /= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } vi = vi += 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } vi += vi = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } i *= vi; - decltype(vi -= 42) x2 = vi; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } + decltype(vi -= 42) x2 = vi; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } // Structured bindings. int a[] = { 10, 5 }; @@ -107,12 +107,12 @@ fn3 () volatile U u; u.c = 42; i = u.c = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } - u.c += 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } + u.c += 42; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } volatile T t; t.a = 3; j = t.a = 3; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } - t.a += 3; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } + t.a += 3; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } volatile int *src = &i; *src; // No assignment, don't warn. @@ -135,7 +135,7 @@ void raccoon () volatile T t, u; t = 42; u = t = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } - t += 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } + t += 42; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } t &= 42; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } } --- gcc/testsuite/g++.dg/cpp2a/volatile3.C.jj 2022-08-16 13:15:22.753043682 +0200 +++ gcc/testsuite/g++.dg/cpp2a/volatile3.C 2022-11-10 23:24:24.781823998 +0100 @@ -75,17 +75,17 @@ fn2 () decltype(i = vi = 42) x3 = i; // Compound assignments. - vi += i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } - vi -= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } - vi %= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } + vi += i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } + vi -= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } + vi %= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } vi ^= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } vi |= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } vi &= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } - vi /= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } + vi /= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } vi = vi += 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } vi += vi = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } i *= vi; - decltype(vi -= 42) x2 = vi; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } + decltype(vi -= 42) x2 = vi; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } // Structured bindings. int a[] = { 10, 5 }; @@ -108,12 +108,12 @@ fn3 () volatile U u; u.c = 42; i = u.c = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } - u.c += 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } + u.c += 42; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } volatile T t; t.a = 3; j = t.a = 3; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } - t.a += 3; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } + t.a += 3; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } volatile int *src = &i; *src; // No assignment, don't warn. @@ -136,7 +136,7 @@ void raccoon () volatile T t, u; t = 42; u = t = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } - t += 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } + t += 42; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } t &= 42; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } } --- gcc/testsuite/g++.dg/cpp2a/volatile5.C.jj 2022-08-16 13:15:22.778043359 +0200 +++ gcc/testsuite/g++.dg/cpp2a/volatile5.C 2022-11-10 23:25:07.445244776 +0100 @@ -7,7 +7,7 @@ void f (bool b) { (b ? x : y) = 1; - (b ? x : y) += 1; // { dg-warning "compound assignment" "" { target c++20 } } + (b ? x : y) += 1; // { dg-bogus "compound assignment" } z = (b ? x : y) = 1; // { dg-warning "using value of assignment" "" { target c++20 } } ((z = 2) ? x : y) = 1; // { dg-warning "using value of assignment" "" { target c++20 } } (b ? (x = 2) : y) = 1; // { dg-warning "using value of assignment" "" { target c++20 } }