From patchwork Tue Jul 16 02:36:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1960860 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=h/c2ejjW; 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 4WNNWL26BDz1xrQ for ; Tue, 16 Jul 2024 12:37:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7B8C4384A49D for ; Tue, 16 Jul 2024 02:37:00 +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 ESMTPS id 0E24D384AB6F for ; Tue, 16 Jul 2024 02:36:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E24D384AB6F 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 0E24D384AB6F 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=1721097400; cv=none; b=oVABwKqG58spoaMiTp6zI72hJI0NuHAw5HCyWP/FZ7vLg0JP1MPzNBt2NuUtTp6yliHjanSuyJPYsADKqjCVw/rmDIzeoxOnpmeSUI0k0KeDLJjW3ZssYRKZDM9JMAQJupTtZTBiQPQtPK3KNd8wDS/pzficTMTdIsc9d66bOLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721097400; c=relaxed/simple; bh=nw/1iUlgrPYYESGgmC9XX6qmnEHEM3dWPFbRl95OflI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=iQbKBM1JjIQhDF5Ks4SDI6M4oSaQM3MZ69MSyzP52DO02eoJzn5QRZqttzAVk/U9OfdjPEjx2lguV/ASeZeDi/woflZbnq1cqNh6wdgNXQPHBJRM3TzYc3NEONhQs2XEFfWDpHMay39rqdsyd0BO+0DCc3Q84oV2h0YWuCLav90= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721097398; 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=gPJz2fHU4BZnN+83nd1XsVxJQUwz2K2vcnHbJgpy+CE=; b=h/c2ejjW78Gde1rlxSNTofpjFeZVxCuoaOaAKHNkyKXHQWS0xfjPK0JwJSEcugMDkmruX+ lMIFPuU5fYrD1MJQeiaUYQGvTK+CsihsxgHGd61DpJ3mwqbjbGyNPn760fX+fMtTKCfAQU ss8Bv4llK+asJzqBuRuzIR5J6voADh4= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-516-NzTqzQR1MH2EuD59owG9UQ-1; Mon, 15 Jul 2024 22:36:37 -0400 X-MC-Unique: NzTqzQR1MH2EuD59owG9UQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-79ef9c44d85so701735885a.1 for ; Mon, 15 Jul 2024 19:36:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721097395; x=1721702195; 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=gPJz2fHU4BZnN+83nd1XsVxJQUwz2K2vcnHbJgpy+CE=; b=BDQeCwdMT+fWevX57kAjY6hrYsGRTeYkHyc4YvNYggaKvG6UkGZ3XvshhvgKEG8uvt x+8N3dqkurgrMs+0LpS/OmgN8rXnPUecTFJ7vrTZGzLRZS6qqTmbbMRbHS97fxF4gduY 57TLcC3n2CDIpgj1dMllyWpVrZCLngpNtaxS2wb9yE5/0tJ/U52ZPuy3AHbPdRgk5CRQ HxDIRbAjlbmzj6JSvodWOZULgBKpqklaOHMpYInq9yQwY5zVnJuL/BG43MRS6GzujQ1p OvCh0O/4AsVK20j2jbfmogFJn6Vn6IA/cNNUI7rN3SBUv/cXX/3CJbLUxpjCCsJfQaCh 5mUg== X-Gm-Message-State: AOJu0YwSOb4yrKy80jxiZ8lwfMxZMlEL1zputk8m3WnntoJA8akwi4gk m2r4MbYc50E54M0qr9oHyVjGfq1WIozZHRzn6onT0l/NlAgdlhjVjPbFEzREA6oyWCf8m+4pA5L /WZpuQSUQnY5BvjERVrtc/4pjdiiN66VmjkU/ZPYXXCX09PeIKSgSb2X3Cn+rOA66HcgF+oi801 0/oIVHh0MgrQBHayR6DRJVLH0DAPv5H7IYPH6d X-Received: by 2002:a05:622a:189b:b0:44c:dadd:3dbc with SMTP id d75a77b69052e-44f7abab3a4mr11056551cf.13.1721097395251; Mon, 15 Jul 2024 19:36:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGEmxRREDJSjWds1owXwxbW3Wo53P//83zISWHBevRmS64XupRZ5Ae3s8wp7i+PEQaiCwREqA== X-Received: by 2002:a05:622a:189b:b0:44c:dadd:3dbc with SMTP id d75a77b69052e-44f7abab3a4mr11056391cf.13.1721097394837; Mon, 15 Jul 2024 19:36:34 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-44f5b8355dbsm30727071cf.76.2024.07.15.19.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jul 2024 19:36:34 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: missing -Wunused-value for ! [PR114104] Date: Mon, 15 Jul 2024 22:36:31 -0400 Message-ID: <20240716023631.906098-1-ppalka@redhat.com> X-Mailer: git-send-email 2.46.0.rc0.35.gad850ef1cf MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 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 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~incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped andrregtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Here we're neglecting to emit a -Wunused-value for eligible ! operator expressions, and in turn for != operator expressions that are rewritten as !(x == y), only because we don't call warn_if_unused_value on TRUTH_NOT_EXPR since its class is tcc_expression. This patch makes us consider warning for TRUTH_NOT_EXPR as well. PR c++/114104 gcc/cp/ChangeLog: * cvt.cc (convert_to_void): Call warn_if_unused_value for TRUTH_NOT_EXPR as well. gcc/testsuite/ChangeLog: * g++.dg/warn/Wunused-20.C: New test. --- gcc/cp/cvt.cc | 1 + gcc/testsuite/g++.dg/warn/Wunused-20.C | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-20.C diff --git a/gcc/cp/cvt.cc b/gcc/cp/cvt.cc index db086c017e8..ebff6db2ea9 100644 --- a/gcc/cp/cvt.cc +++ b/gcc/cp/cvt.cc @@ -1664,6 +1664,7 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) if (tclass == tcc_comparison || tclass == tcc_unary || tclass == tcc_binary + || code == TRUTH_NOT_EXPR || code == VEC_PERM_EXPR || code == VEC_COND_EXPR) warn_if_unused_value (e, loc); diff --git a/gcc/testsuite/g++.dg/warn/Wunused-20.C b/gcc/testsuite/g++.dg/warn/Wunused-20.C new file mode 100644 index 00000000000..6d7838fab13 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-20.C @@ -0,0 +1,17 @@ +// PR c++/114104 +// { dg-additional-options "-Wunused-value" } + +bool f(); + +void g() { + !f(); // { dg-warning "value computed is not used" } +} + +#if __cplusplus >= 202002L +struct A { }; +[[nodiscard]] bool operator==(A, int); + +void g(A a) { + a != 0; // { dg-warning "value computed is not used" "" { target c++20 } } +} +#endif