From patchwork Mon Nov 13 19:01:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 164602 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1414109vqg; Mon, 13 Nov 2023 11:04:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFt+GW7hBTyLQ3aXRJuAKZVKloALEzHpbMaeL0N6RM9IUND0AYqctjaGuZB3kaERhmQh4i7 X-Received: by 2002:a05:6214:1c8d:b0:671:e02a:8bfc with SMTP id ib13-20020a0562141c8d00b00671e02a8bfcmr110052qvb.16.1699902277572; Mon, 13 Nov 2023 11:04:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699902277; cv=pass; d=google.com; s=arc-20160816; b=0Xw7ADEqCdrJNleD3WtXs+hbSQqpRcd7F3Od+/3q3mHkJ4P74kuluwWazdBrSrlBQb obmOuBgAgF8vSp13ibCrBDV4Rud0wM39laIbqtBWu9tbVJCUmIyRxkFGArl6gAFZs3St UjXVNDhUkz34VFshuTtBAgMt8+/NFjcgtkGs+U4qogR9/gDkLoKkx/JImmW6xfMI9gVB VmGsWfVHFTWmX8lzwe4quuPkAuZKcmWM8IfR3RD4ei5NA3lgqNejwwKCbtDTgPcHRYPy faaWG4spusjFD6UBMNwFqSFIDAGVS3hmAfKUOBKFZnc6MIplg+5Kz0w4WFP51uI7ca2+ Yclw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=gfVeIYgJcLLajUnX6cLiMa1jcL2Aj+2iumznhN9xtgk=; fh=QA8fFVv6ggF6fcT+PVnt11ZuEoFb/PawWVLoQ4MwJ9w=; b=mS4DwQQcAnwDCoz5CZ3jlwKi51QNhWMqd4FvAjZMllxazp5NEYFR2KodrReN+yYHhb h+mktxW+TRKbeZA+qrsEZ25NNcG4k0mSqpv8dIB9/uU736tuVtGE4xOkUk/mg0gPXI/y VsXd9lhuY7x9UFLMp0Ykme0i7w3AqPFwO6i1j7HKfvkeTcR0ZniKCt1M29vs5oXUQvRK dgS5zT6wmBzDsAaadzMFAZr2DkRM/P7cuxjcAfO1yDnPZJF8oHXrs184SzqktcePD8Hh WdTK3nMbiB7rY1TvUbJUcyUwEvArgNUP4Je1v1ukdoaVskQ6AaaHNHRy06gBO0YsDTpS 6sYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EhZtLGvS; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w1-20020a0562140b2100b006585ee0fcfesi4810394qvj.74.2023.11.13.11.04.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 11:04:37 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EhZtLGvS; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 50952383F1AB for ; Mon, 13 Nov 2023 19:04:37 +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 579BA3849780 for ; Mon, 13 Nov 2023 19:04:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 579BA3849780 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 579BA3849780 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=1699902254; cv=none; b=bpean+BtKO+wn5G1QrftG3hZWMnnKX5FB5D8F8OwuyrSam4nmq4Aw95I7YEIuRNccjdktSb5oX6Oz7hJCtg/dLZoyoLM73SlbjJYw0k1AaYirUc5fkeza3o60FhgxYGKoVQG31j3sWjcUdh/XrfxWGzoC79lBVSmfjnjZaN5hno= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699902254; c=relaxed/simple; bh=134Dgp6kPd7gf9kXQS3NuedERjv+gReXhxW5hnFmxNA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BjcyOk9OMigllHoWAI7gw/CoG0cf9c/du2PKOjT31lmSPptlVRT5a2f1enlCbjw46t/JAbrTA4BuVzNAGRbYd3+hbnqRi2DikR7FWrLk8v95Ru47CO/AgHl4cEh6iWmELNUTW5ukglFoZcg0oXJSqYKOoMljofbkWFrQOiZ1lTg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699902244; 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=gfVeIYgJcLLajUnX6cLiMa1jcL2Aj+2iumznhN9xtgk=; b=EhZtLGvS37C3ux15TP054iTQTN/1Gtzscs2jdHRj4WLqZFRvbmFrZp9dhe71Q0P8Mgbd5q G0Cpw+N2VKMPQAA95Esk0uifOlkWRcCeKv81sq9GrM9gHb15SjySrsHoQQJ7A2JXANKh+L 6b1kmnzghJ7Ax6PzOcEhCgNbA4jeTjg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-436-AX8YdjQVOGKa67ATtsDQxg-1; Mon, 13 Nov 2023 14:04:02 -0500 X-MC-Unique: AX8YdjQVOGKa67ATtsDQxg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5ABFB88CF74 for ; Mon, 13 Nov 2023 19:04:02 +0000 (UTC) Received: from localhost (unknown [10.42.28.185]) by smtp.corp.redhat.com (Postfix) with ESMTP id 230FD492BFD; Mon, 13 Nov 2023 19:04:02 +0000 (UTC) From: Jonathan Wakely To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Jakub Jelinek Subject: [PATCH] c++: Link extended FP conversion pedwarns to -Wnarrowing [PR111842] Date: Mon, 13 Nov 2023 19:01:18 +0000 Message-ID: <20231113190401.759232-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782476730370725856 X-GMAIL-MSGID: 1782476730370725856 Tested x86_64-linux. Does this make sense for trunk? These forbidden conversions are defined as narrowing conversions, and we already use -Wnarrowing to control other "ill-formed, but only warn by default" diagnostics required by the standard. -- >8 -- Several users have been confused by the status of these warnings, which can be misunderstood as "this might not be what you want", rather than diagnostics required by the C++ standard. Add the text "ISO C++ does not allow" to make this clear. Also link them to -Wnarrowing so that they can be disabled or promoted to errors independently of other pedwarns. gcc/cp/ChangeLog: PR c++/111842 PR c++/112498 * call.cc (convert_like_internal): Use OPT_Wnarrowing for pedwarns about illformed conversions involving extended floating-point types. Clarify that ISO C++ requires these diagnostics. * g++.dg/cpp23/ext-floating16.C: New test. * g++.dg/cpp23/ext-floating17.C: New test. --- gcc/cp/call.cc | 10 +++-- gcc/testsuite/g++.dg/cpp23/ext-floating16.C | 40 ++++++++++++++++++++ gcc/testsuite/g++.dg/cpp23/ext-floating17.C | 42 +++++++++++++++++++++ 3 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp23/ext-floating16.C create mode 100644 gcc/testsuite/g++.dg/cpp23/ext-floating17.C diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 4516677bcab..4b0c6c42f01 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -8303,15 +8303,17 @@ convert_like_internal (conversion *convs, tree expr, tree fn, int argnum, totype)) { case 2: - if (pedwarn (loc, 0, "converting to %qH from %qI with greater " - "conversion rank", totype, TREE_TYPE (expr))) + if (pedwarn (loc, OPT_Wnarrowing, "ISO C++ does not allow " + "converting to %qH from %qI with greater " + "conversion rank", totype, TREE_TYPE (expr))) complained = 1; else if (!complained) complained = -1; break; case 3: - if (pedwarn (loc, 0, "converting to %qH from %qI with unordered " - "conversion ranks", totype, TREE_TYPE (expr))) + if (pedwarn (loc, OPT_Wnarrowing, "ISO C++ does not allow " + "converting to %qH from %qI with unordered " + "conversion rank", totype, TREE_TYPE (expr))) complained = 1; else if (!complained) complained = -1; diff --git a/gcc/testsuite/g++.dg/cpp23/ext-floating16.C b/gcc/testsuite/g++.dg/cpp23/ext-floating16.C new file mode 100644 index 00000000000..d6a562d5cb0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/ext-floating16.C @@ -0,0 +1,40 @@ +// P1467R9 - Extended floating-point types and standard names. +// { dg-do compile { target c++23 } } +// { dg-options "-pedantic-errors -Wno-narrowing" } +// { dg-add-options float16 } +// { dg-add-options float32 } +// { dg-add-options float64 } +// { dg-add-options float128 } + +#include "ext-floating.h" + +#ifdef __STRICT_ANSI__ +#undef __SIZEOF_FLOAT128__ +#endif + +using namespace std; + +#ifdef __STDCPP_FLOAT16_T__ +#ifdef __STDCPP_FLOAT32_T__ +float16_t f16c = 1.0F32; // { dg-bogus "converting to 'std::float16_t' \\\{aka '_Float16'\\\} from '_Float32' with greater conversion rank" "" { target { float16 && float32 } } } +#endif +#ifdef __STDCPP_FLOAT64_T__ +float16_t f16e = 1.0F64; // { dg-bogus "converting to 'std::float16_t' \\\{aka '_Float16'\\\} from '_Float64' with greater conversion rank" "" { target { float16 && float64 } } } +#endif +#ifdef __STDCPP_FLOAT128_T__ +float16_t f16g = 1.0F128; // { dg-bogus "converting to 'std::float16_t' \\\{aka '_Float16'\\\} from '_Float128' with greater conversion rank" "" { target { float16 && float128 } } } +#endif +#endif +#ifdef __STDCPP_FLOAT32_T__ +#ifdef __STDCPP_FLOAT64_T__ +float32_t f32e = 1.0F64; // { dg-bogus "converting to 'std::float32_t' \\\{aka '_Float32'\\\} from '_Float64' with greater conversion rank" "" { target { float32 && float64 } } } +#endif +#ifdef __STDCPP_FLOAT128_T__ +float32_t f32g = 1.0F128; // { dg-bogus "converting to 'std::float32_t' \\\{aka '_Float32'\\\} from '_Float128' with greater conversion rank" "" { target { float32 && float128 } } } +#endif +#endif +#ifdef __STDCPP_FLOAT64_T__ +#ifdef __STDCPP_FLOAT128_T__ +float64_t f64g = 1.0F128; // { dg-bogus "converting to 'std::float64_t' \\\{aka '_Float64'\\\} from '_Float128' with greater conversion rank" "" { target { float64 && float128 } } } +#endif +#endif diff --git a/gcc/testsuite/g++.dg/cpp23/ext-floating17.C b/gcc/testsuite/g++.dg/cpp23/ext-floating17.C new file mode 100644 index 00000000000..796e045537a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/ext-floating17.C @@ -0,0 +1,42 @@ +// P1467R9 - Extended floating-point types and standard names. +// { dg-do compile { target c++23 } } +// { dg-options "-Werror=narrowing" } +// { dg-add-options float16 } +// { dg-add-options float32 } +// { dg-add-options float64 } +// { dg-add-options float128 } +// { dg-prune-output "some warnings being treated as errors" } + +#include "ext-floating.h" + +#ifdef __STRICT_ANSI__ +#undef __SIZEOF_FLOAT128__ +#endif + +using namespace std; + +#ifdef __STDCPP_FLOAT16_T__ +#ifdef __STDCPP_FLOAT32_T__ +float16_t f16c = 1.0F32; // { dg-error "converting to 'std::float16_t' \\\{aka '_Float16'\\\} from '_Float32' with greater conversion rank" "" { target { float16 && float32 } } } +#endif +#ifdef __STDCPP_FLOAT64_T__ +float16_t f16e = 1.0F64; // { dg-error "converting to 'std::float16_t' \\\{aka '_Float16'\\\} from '_Float64' with greater conversion rank" "" { target { float16 && float64 } } } +#endif +#ifdef __STDCPP_FLOAT128_T__ +float16_t f16g = 1.0F128; // { dg-error "converting to 'std::float16_t' \\\{aka '_Float16'\\\} from '_Float128' with greater conversion rank" "" { target { float16 && float128 } } } +#endif +#endif +#ifdef __STDCPP_FLOAT32_T__ +#ifdef __STDCPP_FLOAT64_T__ +float32_t f32e = 1.0F64; // { dg-error "converting to 'std::float32_t' \\\{aka '_Float32'\\\} from '_Float64' with greater conversion rank" "" { target { float32 && float64 } } } +#endif +#ifdef __STDCPP_FLOAT128_T__ +float32_t f32g = 1.0F128; // { dg-error "converting to 'std::float32_t' \\\{aka '_Float32'\\\} from '_Float128' with greater conversion rank" "" { target { float32 && float128 } } } +#endif +#endif +#ifdef __STDCPP_FLOAT64_T__ +#ifdef __STDCPP_FLOAT128_T__ +float64_t f64g = 1.0F128; // { dg-error "converting to 'std::float64_t' \\\{aka '_Float64'\\\} from '_Float128' with greater conversion rank" "" { target { float64 && float128 } } } +#endif +#endif +