From patchwork Wed May 12 16:21:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1477682 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=huw8Oqz9; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FgKpf40Sjz9sRK for ; Thu, 13 May 2021 02:21:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9BCCC3853831; Wed, 12 May 2021 16:21:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9BCCC3853831 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1620836515; bh=85nJyJcnfztwYY796s0hEobtcZ73isAqwSNljwGEt60=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=huw8Oqz9BFhM0g6tzZQkgXaF6xFJdEzOOD55xkSJej7YV2uaIEmaAzxDX9t+aXQy4 /gPFt9B3I1QqakSeVQRMf1CAOV5WID/x3pFcI1sWKUHakxBbVMF5ur5uVwAjEW8boC ZxcCPfXuZWmAUcECfndbI5TyA2sdU6kxLgmWZ18I= 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 ESMTP id 00DBA3853819 for ; Wed, 12 May 2021 16:21:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 00DBA3853819 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-374-8A8tsW90P6GjE41XafmpVQ-1; Wed, 12 May 2021 12:21:51 -0400 X-MC-Unique: 8A8tsW90P6GjE41XafmpVQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 68F07107ACCA for ; Wed, 12 May 2021 16:21:50 +0000 (UTC) Received: from pdp-11.redhat.com (ovpn-117-221.rdu2.redhat.com [10.10.117.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF08C5C8AA; Wed, 12 May 2021 16:21:49 +0000 (UTC) To: Jason Merrill , GCC Patches Subject: [PATCH] c++: Disable -Wint-in-bool-context in instantiations Date: Wed, 12 May 2021 12:21:42 -0400 Message-Id: <20210512162142.438022-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.7 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This warning is of questionable value when it's emitted when instantiating a template, as in the following testcase. It could be silenced by writing hb(i) << 1 instead of 2 * hb(i) but that's unnecessary obfuscation. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? gcc/cp/ChangeLog: * pt.c (tsubst_copy_and_build): Add warn_int_in_bool_context sentinel. gcc/testsuite/ChangeLog: * g++.dg/warn/Wint-in-bool-context-2.C: New test. --- gcc/cp/pt.c | 1 + .../g++.dg/warn/Wint-in-bool-context-2.C | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/Wint-in-bool-context-2.C base-commit: 097fde5e7514e909f2e8472be2e008d0cab2260d diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 85c05af42ed..d7d6a3f2c14 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -19801,6 +19801,7 @@ tsubst_copy_and_build (tree t, warning_sentinel s(warn_useless_cast); warning_sentinel s2(warn_ignored_qualifiers); + warning_sentinel s3(warn_int_in_bool_context); switch (TREE_CODE (t)) { case CAST_EXPR: diff --git a/gcc/testsuite/g++.dg/warn/Wint-in-bool-context-2.C b/gcc/testsuite/g++.dg/warn/Wint-in-bool-context-2.C new file mode 100644 index 00000000000..6cb482d4dc9 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wint-in-bool-context-2.C @@ -0,0 +1,16 @@ +// { dg-do compile { target c++11 } } +// { dg-options "-Wint-in-bool-context" } + +unsigned hb(unsigned i) { return ~i; } + +template +void f(int i) +{ + auto l = [i]() { return T(2 * hb(i)); }; // { dg-bogus "in boolean context" } + (void) l; +} + +int main() +{ + f(0); +}