From patchwork Sat Mar 25 10:10:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 74886 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp356505vqo; Sat, 25 Mar 2023 04:54:46 -0700 (PDT) X-Google-Smtp-Source: AKy350b5uviZReU8/zCGcsXLIvgoqUrOONG7DpCzzOrkwyiF22Y34+Ei4FFOmle+7wOYVMCfshOR X-Received: by 2002:a05:6402:658:b0:4fb:6523:2b38 with SMTP id u24-20020a056402065800b004fb65232b38mr6302633edx.27.1679745286743; Sat, 25 Mar 2023 04:54:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679745286; cv=none; d=google.com; s=arc-20160816; b=Bm/7myYigECsN756r4+Dro+BRPFWqDZLbCKiTlms0ZodG7LzQKV/qbzOMZTSSbD5ZH O/9PV/wXmZSgnCuxbl1j3+pMLYuPDmssOYmWXwN04jXubJ7yEJObfjzUr1iTgVbEdvr3 z3Ox2DuaqiIETFMNjTi0tyuo5y5VmmKgJrTXixNi9UI7z06kzdJDxThe4WlsWyOvd7sf ppai/ct46upFnjt+YNWKzN4g+tebUcJOE0AzE/rFSXaw9zPYLkArhc5TJtBFiIs18H2Y a65M6baynMoROTGNNDis5MIOo+oRU2187iwSFOlT6sDpGBcjyHXGx5994UQv9oe8KkK8 dx/Q== 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:to:date :resent-to:resent-message-id:resent-date:resent-from:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=jPTJ1XPH9dXD1TEjNna97/y3iCyrmj4UDsdwM006gmc=; b=Nt5BWHGVEgMD9f/dKRAno8RxQmDudYFRvluW3sGwObzvtDAmBEo+Vjp7LfLZuagJZ1 WLuVEXv+tpp20OiccRkCH1fZnBePp3bFbFpj5jTNlGuEIdFuhq1+9DdBIvQmHX2XjKaK pD4KfPFJm0TMkm78ZFH2TgMalwPKxf1JRFppNbGoaQWARilK/zrK2YIOzxXeB15ik7Cs yZlZSO/TOXsJL6g7tHyU+iiPx5XgJWP0uUGFYUPfcaRBKnQdefJaZOZIi+0HqMJBcuiP nwYqj59KgIjcR/GTwOdnSZYhJx5C0VyjYcMRUV8OK/NrgKomBidgE38qKUEWZk42cEbL UT7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=x3DexXek; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id s3-20020a056402164300b004fb160705c4si16163284edx.367.2023.03.25.04.54.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 04:54:46 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=x3DexXek; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 A5F6B3857352 for ; Sat, 25 Mar 2023 11:54:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A5F6B3857352 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679745285; bh=jPTJ1XPH9dXD1TEjNna97/y3iCyrmj4UDsdwM006gmc=; h=Resent-From:Resent-Date:Resent-To:Date:To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=x3DexXek0prbzoPfkYhx8Pbzni+fOprcmdK4IdUNs8tzs7OiTpuCzJKA9xvVck02n t+lxSyXuSz8M5wtko73Cquktm3zyFlMcpKWgo5VJEmi8a01QGPGEYzf3bCsOyQbNxw Uz6rVP0XFBanyk9u8NAA0v//nHttjEFnKODB9YkM= 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 0CF923858D1E for ; Sat, 25 Mar 2023 11:54:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0CF923858D1E 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-481-RIJ5tlNXPn-6Urg6PLnqnQ-1; Sat, 25 Mar 2023 07:54:00 -0400 X-MC-Unique: RIJ5tlNXPn-6Urg6PLnqnQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 581D78533DF for ; Sat, 25 Mar 2023 11:54:00 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1BC48202701E for ; Sat, 25 Mar 2023 11:54:00 +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 32PBrqhZ3360549 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Sat, 25 Mar 2023 12:53:53 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32PBrqL53360548 for gcc-patches@gcc.gnu.org; Sat, 25 Mar 2023 12:53:52 +0100 Resent-From: Jakub Jelinek Resent-Date: Sat, 25 Mar 2023 12:53:52 +0100 Resent-Message-ID: Resent-To: gcc-patches@gcc.gnu.org Date: Sat, 25 Mar 2023 11:10:54 +0100 To: Jason Merrill , gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Avoid informs without a warning [PR109278] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.3 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?1761340594061401645?= X-GMAIL-MSGID: =?utf-8?q?1761340594061401645?= Hi! On the following testcase we emit notes in maybe_inform_about_fndecl_for_bogus_argument_init despite no warning/error being printed before it. This is for the extended floating point type conversions where pedwarn is used, and complained is used there for 2 different purposes, one is whether an unspecific error should be emitted if we haven't complained otherwise, and one whether maybe_inform_about_fndecl_for_bogus_argument_init should be called. For the 2 pedwarns, currently it sets complained to true regardless of whether pedwarn succeeded, which results in the undesirable notes printed with -w. If complained is initialized to result of pedwarn, we would emit an error later on. So, the following patch makes complained a tristate, the additional error isn't printed if complained != 0, and maybe_inform_about_fndecl_for_bogus_argument_init is called only if complained == 1, so if pedwarn returns false, we can use complained = -1 to tell later code not to emit an error and not to call maybe_inform_about_fndecl_for_bogus_argument_init. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-03-25 Jakub Jelinek PR c++/109278 * call.cc (convert_like_internal): If pedwarn for extended float type conversions doesn't report anything, avoid calling maybe_inform_about_fndecl_for_bogus_argument_init. * g++.dg/cpp23/ext-floating15.C: New test. Jakub --- gcc/cp/call.cc.jj 2023-03-23 15:24:33.074801422 +0100 +++ gcc/cp/call.cc 2023-03-24 22:29:06.328140170 +0100 @@ -8296,7 +8296,7 @@ convert_like_internal (conversion *convs || SCALAR_TYPE_P (totype)) && convs->kind != ck_base) { - bool complained = false; + int complained = 0; conversion *t = convs; /* Give a helpful error if this is bad because of excess braces. */ @@ -8328,14 +8328,18 @@ convert_like_internal (conversion *convs totype)) { case 2: - pedwarn (loc, 0, "converting to %qH from %qI with greater " - "conversion rank", totype, TREE_TYPE (expr)); - complained = true; + if (pedwarn (loc, 0, "converting to %qH from %qI with greater " + "conversion rank", totype, TREE_TYPE (expr))) + complained = 1; + else if (!complained) + complained = -1; break; case 3: - pedwarn (loc, 0, "converting to %qH from %qI with unordered " - "conversion ranks", totype, TREE_TYPE (expr)); - complained = true; + if (pedwarn (loc, 0, "converting to %qH from %qI with unordered " + "conversion ranks", totype, TREE_TYPE (expr))) + complained = 1; + else if (!complained) + complained = -1; break; default: break; @@ -8389,7 +8393,7 @@ convert_like_internal (conversion *convs "invalid conversion from %qH to %qI", TREE_TYPE (expr), totype); } - if (complained) + if (complained == 1) maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum); return cp_convert (totype, expr, complain); --- gcc/testsuite/g++.dg/cpp23/ext-floating15.C.jj 2023-03-24 22:38:40.358890548 +0100 +++ gcc/testsuite/g++.dg/cpp23/ext-floating15.C 2023-03-24 22:38:18.484204916 +0100 @@ -0,0 +1,11 @@ +// PR c++/109278 +// { dg-do compile { target float128 } } +// { dg-options "-w" } + +void foo (long double); // { dg-bogus "initializing argument 1 of" } + +void +bar (_Float128 x) +{ + foo (x); +}