From patchwork Wed Nov 29 19:42:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 80983 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 9A0E53870C0D for ; Wed, 29 Nov 2023 19:42:40 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 491DE3858C2F for ; Wed, 29 Nov 2023 19:42:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 491DE3858C2F 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 491DE3858C2F 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=1701286944; cv=none; b=Aw4jUcwMtIwztRF5czD4IdZGG/8fF9nputWlUM+khpwz+B7UVrkM03Et8gsWr/nAPBVROOKLNepD89qvbUrIUVfPMJqxVCC9QJ87xyowblwSomKI9J/A8/p4BMOYXnXwGv5fb+jngEV7oUD3zoP4xftReCZljCAtyuwV+kbUO6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701286944; c=relaxed/simple; bh=3NuhbhQkefOFXharuKCB4DEp8KhZoZ3yL/2ljz4peLo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=bs7OArhR2DgAt9YpyZvhORKv53kYHQI1erxiA19rzBOzH4/chqsloOIetybop5MhG3XaedLizJD4fPXUlnW1cfxQI4KhE64wina+hi+hXsQ40zcg54dcXz0nSLAipfidML3PL3Tcw7BabBess8VchV+Qb3jx5fAEqwWPT8/W348= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701286942; 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=YzdyVdcDXudmmIXWkckgiF2bRYxt1yf1dmD/fxXmaY4=; b=J0ymCEyF5y9a/V1kDetnxLiyOe1fFgEKZ+nGy8/QPlhqygKgcXgkS/1rk1uG7u7IwDdgln Tu9VTHsNIrBhkBi3bHO5g/faDhj452OT9/PplT2hTUpO0d1JjM6lkIJrWm3W8R68Almnna phgFC6YdrT3lTgqVOVHVwxh6mUHgIsI= Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-413-pwR6LfE6NAWcAWu7zmackA-1; Wed, 29 Nov 2023 14:42:21 -0500 X-MC-Unique: pwR6LfE6NAWcAWu7zmackA-1 Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3b892926906so160961b6e.0 for ; Wed, 29 Nov 2023 11:42:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701286939; x=1701891739; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YzdyVdcDXudmmIXWkckgiF2bRYxt1yf1dmD/fxXmaY4=; b=Hya5uE09Rktg5pIla1Nk0cWtFtwVqAOZN0VarRldqzInszTNu3W0QuSHby/hok7DId vMYKKH1bNorieVz+UDHFnHzLnKLtqOblA+i5GITy/khWMKHyckJeDB1FA8ggg6HK3gEK Z6GJjOujg4+Df6+73yL3WWa3636nXcusXHb6mXeSzhCTe/B5tBi5w1+LRqeJ7VbnIZoy BDiCF6Q478d9ixt9EPNhsgPdQ0LqivKcT5LiU9qCKtLh/9Ckhoz/1Oax+4SyfN8dm1Im /kH8QqOTc0NmmQX9MbBGs61i3iYZgIgUIvisFQJjNMrzBmmXXhbW/4ZEp+UyJ3KP3JA5 show== X-Gm-Message-State: AOJu0YxUGO90z7tOFHR4D+3ZfgBbNDMjpkwMjl5adG/ZI0RPgZ1uGhN5 b7G3eNnNh2aZtZ/D6rv97ltxYl9FChWJa6h0GkwM4XFb3VE2m5LOrzjRJ7T2yfkTApVJR3RcPnt 6Xxn5ce+vE/foXh8v8JDT2N3SdgOuOROdGALx0ePrDy+YNI6UgrVnSGSZNVnzxBiuWHXTfCOc3e I= X-Received: by 2002:a05:6808:1488:b0:3b8:402d:578b with SMTP id e8-20020a056808148800b003b8402d578bmr27831645oiw.25.1701286939334; Wed, 29 Nov 2023 11:42:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDiBM3Qpx58qZZMujULBVgj0eDfzDLnuqxzMuPPNlw9yvlRM5MHFBV/0WA7PCbv23A2JD23A== X-Received: by 2002:a05:6808:1488:b0:3b8:402d:578b with SMTP id e8-20020a056808148800b003b8402d578bmr27831614oiw.25.1701286938872; Wed, 29 Nov 2023 11:42:18 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id g5-20020ae9e105000000b0077d749de2a3sm5585919qkm.67.2023.11.29.11.42.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 11:42:18 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: bogus -Wparentheses warning [PR112765] Date: Wed, 29 Nov 2023 14:42:10 -0500 Message-ID: <20231129194210.2626367-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.rc1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.6 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 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+patchwork=sourceware.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linu-xgnu, does this look OK for trunk? -- >8 -- We need to consistently look through implicit INDIRECT_REF when setting/checking for -Wparentheses warning suppression. In passing use STRIP_REFERENCE_REF consistently as well. PR c++/112765 gcc/cp/ChangeLog: * pt.cc (tsubst_expr) : Look through implicit INDIRECT_REF when propagating -Wparentheses warning suppression. * semantics.cc (maybe_warn_unparenthesized_assignment): Replace REFERENCE_REF_P stripping with STRIP_REFERENCE_REF. (finish_parenthesized_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/warn/Wparentheses-33.C: New test. --- gcc/cp/pt.cc | 2 +- gcc/cp/semantics.cc | 6 ++---- gcc/testsuite/g++.dg/warn/Wparentheses-33.C | 24 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-33.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 00b095265b6..fc4464dec02 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -20282,7 +20282,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) build_x_modify_expr sets it and it must not be reset here. */ if (warning_suppressed_p (t, OPT_Wparentheses)) - suppress_warning (r, OPT_Wparentheses); + suppress_warning (STRIP_REFERENCE_REF (r), OPT_Wparentheses); RETURN (r); } diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 3bf586453dc..fc00c20cba4 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -871,8 +871,7 @@ is_assignment_op_expr_p (tree t) void maybe_warn_unparenthesized_assignment (tree t, tsubst_flags_t complain) { - if (REFERENCE_REF_P (t)) - t = TREE_OPERAND (t, 0); + t = STRIP_REFERENCE_REF (t); if ((complain & tf_warning) && warn_parentheses @@ -2176,8 +2175,7 @@ finish_parenthesized_expr (cp_expr expr) { /* This inhibits warnings in maybe_warn_unparenthesized_assignment and c_common_truthvalue_conversion. */ - tree inner = REFERENCE_REF_P (expr) ? TREE_OPERAND (expr, 0) : *expr; - suppress_warning (inner, OPT_Wparentheses); + suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses); } if (TREE_CODE (expr) == OFFSET_REF diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-33.C b/gcc/testsuite/g++.dg/warn/Wparentheses-33.C new file mode 100644 index 00000000000..6c65037d1b4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-33.C @@ -0,0 +1,24 @@ +// PR c++/112765 + +struct A { + A& operator=(const A&); + operator bool() const; +}; + +template +void f(A a1, A a2) { + if ((a2 = a1)) // { dg-bogus "suggest parentheses" } + return; + bool b = (a2 = a1); // { dg-bogus "suggest parentheses" } +} + +template void f(A, A); + +template +void g(T a1, T a2) { + if ((a2 = a1)) // { dg-bogus "suggest parentheses" } + return; + bool b = (a2 = a1); // { dg-bogus "suggest parentheses" } +} + +template void g(A, A);