From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 B96D7385D0FB for ; Mon, 31 Oct 2022 17:05:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B96D7385D0FB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667235917; 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: in-reply-to:in-reply-to:references:references; bh=2XaDZ4N84JLXc6tncjOwikQWRD1ArDMKwuQXp+A5lkc=; b=KAF1qYyVmmMkTrVvdEoA6nKdEhVSO7Tj1/k6ISMa8PZcANm0pmB6Uvf4JYnRvltmYnuPAL e3s6/+keRbL2J3OtTEtsT5zpUu17knEvpdhHhLZRWgT0TOS89UPFtIIymkh7hggvbmuCtr j7AzRmltReefen1MfEYQ0VL08tNWsy0= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-650-hieq5dmUNKSsa5eoNhz_Bw-1; Mon, 31 Oct 2022 13:05:11 -0400 X-MC-Unique: hieq5dmUNKSsa5eoNhz_Bw-1 Received: by mail-ej1-f71.google.com with SMTP id hc43-20020a17090716ab00b0078e28567ffbso6352644ejc.15 for ; Mon, 31 Oct 2022 10:05:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2XaDZ4N84JLXc6tncjOwikQWRD1ArDMKwuQXp+A5lkc=; b=eUkICZOjKdl7GL8MIa4sl+wRm0T0spxn3NgQkY0CHQNEvqkzQpEbRbjYmSLdB7J8eZ FH6O04WvNYaTrMtbuJGvIsJ8WX8wieNX7O0ay9YvYnXb7/fPwB437FJQ62KVLOIz9BqX j31IJDsaQGudl0LhZGhyTWIfIm3YOfAqZ/K8RRWFdNwN6Jc7b6hTXtSAnuPxIqHn1VgX K73R+H7exd6IuA5lP/ISlS1vNVvNOl24eg/kr0kbOysfaV44eUP7YTKUuAuOb7ryP4OF tzCASPG+Z19uNU6xJZkhmqWEWoiE9zBEdMXcavj6MymCfXh5TNrKltaTh+W6CKju0xob Z4pQ== X-Gm-Message-State: ACrzQf3PQe3p/olfkZSUDAMq5wWxjAY88Tg9MyW6C2PUzIlQWO3DoXLK GtQr8kbBbSKr0424Edpk3htxksI0oOvVtCDczektxfgg6NVIwzmfYSbWWviSPgOEMjfHPflFrIc pcnGtPlyuOfQmhqc8lex4QdYLbrw0T/E= X-Received: by 2002:a05:6402:1292:b0:463:27a0:72b4 with SMTP id w18-20020a056402129200b0046327a072b4mr9855588edv.419.1667235910140; Mon, 31 Oct 2022 10:05:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4WrIHr9nrbT+s+rrZczgmjQnDIln03F+1LfQ/H1WWue1BFZiX9NQbibMXRzgxiRCSaUR4Zq3ibZwB0ll+ZScA= X-Received: by 2002:a05:6402:1292:b0:463:27a0:72b4 with SMTP id w18-20020a056402129200b0046327a072b4mr9855562edv.419.1667235909844; Mon, 31 Oct 2022 10:05:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Mon, 31 Oct 2022 17:04:58 +0000 Message-ID: Subject: Re: [PATCH] libstdc++-v3: support for extended floating point types To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,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 List-Id: On Mon, 31 Oct 2022 at 16:57, Jakub Jelinek wrote: > > On Mon, Oct 31, 2022 at 10:26:11AM +0000, Jonathan Wakely wrote: > > > --- libstdc++-v3/include/std/complex.jj 2022-10-21 08:55:43.037675332= +0200 > > > +++ libstdc++-v3/include/std/complex 2022-10-21 17:05:36.802243229= +0200 > > > @@ -142,8 +142,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > > > > > /// Converting constructor. > > > template > > > +#if __cplusplus > 202002L > > > + explicit(!requires(_Up __u) { _Tp{__u}; }) > > > + constexpr complex(const complex<_Up>& __z) > > > + : _M_real(_Tp(__z.real())), _M_imag(_Tp(__z.imag())) { } > > > > Do these casts to _Tp do anything? The _M_real and _M_imag members are > > already of type _Tp and we're using () initialization not {} so > > there's no narrowing concern. _M_real(__z.real()) is already an > > explicit conversion from decltype(__z.real()) to decltype(_M_real) so > > the extra _Tp is redundant. > > If I use just > : _M_real(__z.real()), _M_imag(__z.imag()) { } > then without -Wsystem-headers there are no regressions, but compiling > g++.dg/cpp23/ext-floating12.C with additional -Wsystem-headers > -pedantic-errors results in lots of extra errors on that line: > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98_Float32=E2=80=99 from =E2=80=98double=E2=80=99 with grea= ter conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98_Float32=E2=80=99 from =E2=80=98double=E2=80=99 with grea= ter conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98_Float32=E2=80=99 from =E2=80=98long double=E2=80=99 with= greater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98_Float32=E2=80=99 from =E2=80=98long double=E2=80=99 with= greater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98_Float32=E2=80=99 from =E2=80=98_Float64=E2=80=99 with gr= eater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98_Float32=E2=80=99 from =E2=80=98_Float64=E2=80=99 with gr= eater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98_Float32=E2=80=99 from =E2=80=98_Float128=E2=80=99 with g= reater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98_Float32=E2=80=99 from =E2=80=98_Float128=E2=80=99 with g= reater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98_Float64=E2=80=99 from =E2=80=98long double=E2=80=99 with= greater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98_Float64=E2=80=99 from =E2=80=98long double=E2=80=99 with= greater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98_Float64=E2=80=99 from =E2=80=98_Float128=E2=80=99 with g= reater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98_Float64=E2=80=99 from =E2=80=98_Float128=E2=80=99 with g= reater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98_Float16=E2=80=99 from =E2=80=98float=E2=80=99 with great= er conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98_Float16=E2=80=99 from =E2=80=98float=E2=80=99 with great= er conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98_Float16=E2=80=99 from =E2=80=98double=E2=80=99 with grea= ter conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98_Float16=E2=80=99 from =E2=80=98double=E2=80=99 with grea= ter conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98_Float16=E2=80=99 from =E2=80=98long double=E2=80=99 with= greater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98_Float16=E2=80=99 from =E2=80=98long double=E2=80=99 with= greater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98_Float16=E2=80=99 from =E2=80=98_Float32=E2=80=99 with gr= eater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98_Float16=E2=80=99 from =E2=80=98_Float32=E2=80=99 with gr= eater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98_Float16=E2=80=99 from =E2=80=98_Float64=E2=80=99 with gr= eater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98_Float16=E2=80=99 from =E2=80=98_Float64=E2=80=99 with gr= eater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98_Float16=E2=80=99 from =E2=80=98_Float128=E2=80=99 with g= reater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98_Float16=E2=80=99 from =E2=80=98_Float128=E2=80=99 with g= reater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98_Float16=E2=80=99 from =E2=80=98__bf16=E2=80=99 with unor= dered conversion ranks > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98_Float16=E2=80=99 from =E2=80=98__bf16=E2=80=99 with unor= dered conversion ranks > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98__bf16=E2=80=99 from =E2=80=98float=E2=80=99 with greater= conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98__bf16=E2=80=99 from =E2=80=98float=E2=80=99 with greater= conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98__bf16=E2=80=99 from =E2=80=98double=E2=80=99 with greate= r conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98__bf16=E2=80=99 from =E2=80=98double=E2=80=99 with greate= r conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98__bf16=E2=80=99 from =E2=80=98long double=E2=80=99 with g= reater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98__bf16=E2=80=99 from =E2=80=98long double=E2=80=99 with g= reater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98__bf16=E2=80=99 from =E2=80=98_Float32=E2=80=99 with grea= ter conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98__bf16=E2=80=99 from =E2=80=98_Float32=E2=80=99 with grea= ter conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98__bf16=E2=80=99 from =E2=80=98_Float64=E2=80=99 with grea= ter conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98__bf16=E2=80=99 from =E2=80=98_Float64=E2=80=99 with grea= ter conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98__bf16=E2=80=99 from =E2=80=98_Float128=E2=80=99 with gre= ater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98__bf16=E2=80=99 from =E2=80=98_Float128=E2=80=99 with gre= ater conversion rank > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: conve= rting to =E2=80=98__bf16=E2=80=99 from =E2=80=98_Float16=E2=80=99 with unor= dered conversion ranks > .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: conve= rting to =E2=80=98__bf16=E2=80=99 from =E2=80=98_Float16=E2=80=99 with unor= dered conversion ranks > > __z doesn't have _Tp type, but _Up, which is some other floating Right. > point type. For the conversion constructors where we have > explicit(false) all is fine, we've tested in the requires that > _Up is implicitly convertable to _Tp. > But if explicit(true), it is fine without the explicit casts only > for long double -> float, long double -> double and double -> float > casts which are ok for implicit casts but not in narrowing conversions > with non-constants. > Otherwise it results in the above diagnostics. That seems like a compiler bug. I don't see any reason for val(x) to be different from val(T(x)) when T is decltype(val). They are both direct-initialization of T from x. > > > I think the diff between C++23 and older standards would be smaller > > done like this: > > > > /// Converting constructor. > > template > > #if __cplusplus > 202002L > > explicit(!requires(_Up __u) { _Tp{__u}; }) > > #endif > > _GLIBCXX_CONSTEXPR complex(const complex<_Up>& __z) > > : _M_real(__z.real()), _M_imag(__z.imag()) { } > > I could go for this with the _Tp() casts everywhere, or > make also that line (perhaps except for { }) also conditional on > #if __cplusplus > 202002L. > > > This also means the constructor body is always defined on the same > > line, which avoids warnings from ld.gold's -Wodr-violations which IIRC > > is based on simple heuristics like the line where the function is > > defined. > > > > Otherwise this looks great. If the above alternative works, please use > > that, but OK for trunk either way (once all the other patches it > > depends on are in). > > All the builtins patches are in since today, and the > "Small extended float support tweaks" patch is in too (it had a small > testsuite conflict due to the > https://gcc.gnu.org/pipermail/libstdc++/2022-October/054849.html > patch still pending, but I've just resolved that conflict). > I think this patch doesn't depend on anything anymore. > > OT, I also get on the same testcase with -Wsystem-headers -pedantic-error= s > .../x86_64-pc-linux-gnu/libstdc++-v3/include/cmath:47:2: error: #include_= next is a GCC extension > .../x86_64-pc-linux-gnu/libstdc++-v3/include/bits/std_abs.h:38:2: error: = #include_next is a GCC extension > .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-st= andard suffix on floating constant [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-st= andard suffix on floating constant [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-st= andard suffix on floating constant [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-st= andard suffix on floating constant [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-st= andard suffix on floating constant [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-st= andard suffix on floating constant [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-st= andard suffix on floating constant [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-st= andard suffix on floating constant [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-st= andard suffix on floating constant [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-st= andard suffix on floating constant [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-st= andard suffix on floating constant [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-st= andard suffix on floating constant [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-st= andard suffix on floating constant [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/cstdlib:79:2: error: #includ= e_next is a GCC extension > .../libstdc++-v3/libsupc++/compare:844:45: error: ISO C++ does not suppor= t =E2=80=98__int128=E2=80=99 for =E2=80=98type name=E2=80=99 [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/cstddef:91:36: error: ISO C+= + does not support =E2=80=98__int128=E2=80=99 for =E2=80=98type name=E2=80= =99 [-Wpedantic] > .../x86_64-pc-linux-gnu/libstdc++-v3/include/cstddef:93:45: error: ISO C+= + does not support =E2=80=98__int128=E2=80=99 for =E2=80=98type name=E2=80= =99 [-Wpedantic] > For the numbers case (__float128 in there), wonder if we can wrap it in _= _extension__ or > use __extension__ __float128 as the type (apparently e.g. type_traits use= s > __extension__ before the template keyword of the specializations), for th= e __int128 cases perhaps > too, no idea about #include_next though. Yeah, __extension__ works in some places, although I think I've found places it doesn't help. The #include_next one has no way to disable it, which is annoying.