From patchwork Tue Nov 12 16:44:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1193685 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-513152-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="VNWAPSx1"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="B2Qe3kv6"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47CDBd1Rtbz9sPL for ; Wed, 13 Nov 2019 03:45:27 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=PPy9uAPR+bBJ67WN yz7H2Kc3C75EE97F4jQS5gc0INk0LiV9njr7AJFCh84wmXIyYN6XjB3dZr7nkQox gEjfB1o2daFCkpnRyHKEMvRcH8WirUz2R8Zm/3kKSWQ324qP+DA+uUXMQaeLc+LQ /m0h/FB3lGhBkNL8SeUxS4LPnVQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=s85ifwgj9TV1BCYomBrj3g UVG8Q=; b=VNWAPSx1gUto1tH7mn2gewl7qF44it2EW1WwUABVNScMtGNDbCKBRL tt4uvneDv7uaptZntgJC7MOC1kHCj9/kJRcQT1JE0dkdJZ1H1v7sLlG1lgEQaXsM 38PzgMIasyZHj20QGm0i4O5H6ZKFmDXt2dNK+ZZmkPh8uFahGgguo= Received: (qmail 125651 invoked by alias); 12 Nov 2019 16:45:04 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 125626 invoked by uid 89); 12 Nov 2019 16:45:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=cpp1z X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Nov 2019 16:45:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573577100; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1UE7jBdDkVuY8y+19Nf0H2BRS+H+taD9sEUtUnwfO3s=; b=B2Qe3kv6/l6EhxFED6B/vAKK8W6ryV6fIaCbqMXpYSrt+o/xg3hIc9Yvm5uapI/MJ8WNx5 M/R7xF+RKUxdW3dxqN0sCG3kySkJEbaBFhrNqSCu7OLwKLsdbIOijY8/76uIUjBpcVUICj xIcCCQtVg9tzLKiL2ThDZC0y4ezWUUY= 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-48-Q5oIEmDEN7mH-6oziVpaKQ-1; Tue, 12 Nov 2019 11:44:59 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D5511005502 for ; Tue, 12 Nov 2019 16:44:58 +0000 (UTC) Received: from redhat.com (ovpn-125-4.rdu2.redhat.com [10.10.125.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF9915DE7B; Tue, 12 Nov 2019 16:44:57 +0000 (UTC) Date: Tue, 12 Nov 2019 11:44:55 -0500 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [C++ PATCH] c++/89070 - bogus [[nodiscard]] warning in SFINAE. Message-ID: <20191112164455.GD3791@redhat.com> MIME-Version: 1.0 User-Agent: Mutt/1.12.1 (2019-06-15) X-Mimecast-Spam-Score: 0 Content-Disposition: inline This is a complaint that we issue a [[nodiscard]] warning even in SFINAE contexts. Here 'complain' is tf_decltype, but not tf_warning so I guess we can fix it as below. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2019-11-12 Marek Polacek PR c++/89070 - bogus [[nodiscard]] warning in SFINAE. * cvt.c (convert_to_void): Guard maybe_warn_nodiscard calls with tf_warning. * g++.dg/cpp1z/nodiscard7.C: New test. diff --git gcc/cp/cvt.c gcc/cp/cvt.c index d41aeb8f1fc..23facb77634 100644 --- gcc/cp/cvt.c +++ gcc/cp/cvt.c @@ -1201,7 +1201,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) if (DECL_DESTRUCTOR_P (fn)) return expr; - maybe_warn_nodiscard (expr, implicit); + if (complain & tf_warning) + maybe_warn_nodiscard (expr, implicit); break; case INDIRECT_REF: @@ -1357,7 +1358,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) && !is_reference) warning_at (loc, OPT_Wunused_value, "value computed is not used"); expr = TREE_OPERAND (expr, 0); - if (TREE_CODE (expr) == CALL_EXPR) + if (TREE_CODE (expr) == CALL_EXPR + && (complain & tf_warning)) maybe_warn_nodiscard (expr, implicit); } @@ -1435,7 +1437,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) AGGR_INIT_EXPR_ARGP (init)); } } - maybe_warn_nodiscard (expr, implicit); + if (complain & tf_warning) + maybe_warn_nodiscard (expr, implicit); break; default:; diff --git gcc/testsuite/g++.dg/cpp1z/nodiscard7.C gcc/testsuite/g++.dg/cpp1z/nodiscard7.C new file mode 100644 index 00000000000..80dac63e41e --- /dev/null +++ gcc/testsuite/g++.dg/cpp1z/nodiscard7.C @@ -0,0 +1,18 @@ +// PR c++/89070 - bogus [[nodiscard]] warning in SFINAE. +// { dg-do compile { target c++11 } } + +struct A +{ + [[nodiscard]] static int match() { return 42; } +}; + +template +auto g() -> decltype( T::match(), bool() ) +{ + return T::match(); +} + +int main() +{ + g(); +}