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: 66883 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 4CE5C384F01A for ; Sat, 25 Mar 2023 11:54:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CE5C384F01A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679745270; 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=GD8uoWlx0yl5sRQ2fih0sAiSWLe4HtiKG7I7oVHfJshID1G5T6UF08jX/vQ2Wakzy Ru6O7+W/GnXvryYNCjsTy5L9Fa/zZkPgQNj4kqdCcdIzqameocz88xt+IyfQ5TaOBH CgQd46ZuEVymZFuqd7mmh3flt/EoIBnXFChoowSQ= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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); +}