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 373AD385D0D2 for ; Mon, 31 Oct 2022 16:57:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 373AD385D0D2 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=1667235464; h=from:from:reply-to: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=cl3ZYuCUtMXCZ+kl8I11mc0YLkbUUQeELhHU+lxkuy0=; b=PxU9U2ltomkx2p7VxnrPTD6F9Eb4PloCUXi5hyPOQIe1iBcNGziKYV80BcNi3zRGXzwKmU F4YeYX2QnXlDeU+1uw6fC5Onzo85nEHR7mfGE2UR/NFxVZus99kr1UzkUUvrANbu4DCOG+ SSsumFqqku4eMeVJ5bDL0i8P4619Qok= 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-54-6gn36h6uPEuQ2OopTymLdw-1; Mon, 31 Oct 2022 12:57:42 -0400 X-MC-Unique: 6gn36h6uPEuQ2OopTymLdw-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 35A66800159; Mon, 31 Oct 2022 16:57:42 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.252]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA5262024CB7; Mon, 31 Oct 2022 16:57:41 +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 29VGvdJs2332486 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 31 Oct 2022 17:57:39 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 29VGvcmT2332485; Mon, 31 Oct 2022 17:57:38 +0100 Date: Mon, 31 Oct 2022 17:57:33 +0100 From: Jakub Jelinek To: Jonathan Wakely Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: Re: [PATCH] libstdc++-v3: support for extended floating point types Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.0 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, 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: converting to ‘_Float32’ from ‘double’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘_Float32’ from ‘double’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘_Float32’ from ‘long double’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘_Float32’ from ‘long double’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘_Float32’ from ‘_Float64’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘_Float32’ from ‘_Float64’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘_Float32’ from ‘_Float128’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘_Float32’ from ‘_Float128’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘_Float64’ from ‘long double’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘_Float64’ from ‘long double’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘_Float64’ from ‘_Float128’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘_Float64’ from ‘_Float128’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘_Float16’ from ‘float’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘_Float16’ from ‘float’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘_Float16’ from ‘double’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘_Float16’ from ‘double’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘_Float16’ from ‘long double’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘_Float16’ from ‘long double’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘_Float16’ from ‘_Float32’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘_Float16’ from ‘_Float32’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘_Float16’ from ‘_Float64’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘_Float16’ from ‘_Float64’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘_Float16’ from ‘_Float128’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘_Float16’ from ‘_Float128’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘_Float16’ from ‘__bf16’ with unordered conversion ranks .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘_Float16’ from ‘__bf16’ with unordered conversion ranks .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘__bf16’ from ‘float’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘__bf16’ from ‘float’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘__bf16’ from ‘double’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘__bf16’ from ‘double’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘__bf16’ from ‘long double’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘__bf16’ from ‘long double’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘__bf16’ from ‘_Float32’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘__bf16’ from ‘_Float32’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘__bf16’ from ‘_Float64’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘__bf16’ from ‘_Float64’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘__bf16’ from ‘_Float128’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘__bf16’ from ‘_Float128’ with greater conversion rank .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:27: error: converting to ‘__bf16’ from ‘_Float16’ with unordered conversion ranks .../x86_64-pc-linux-gnu/libstdc++-v3/include/complex:149:48: error: converting to ‘__bf16’ from ‘_Float16’ with unordered conversion ranks __z doesn't have _Tp type, but _Up, which is some other floating 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. > 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-errors .../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-standard suffix on floating constant [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-standard suffix on floating constant [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-standard suffix on floating constant [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-standard suffix on floating constant [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-standard suffix on floating constant [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-standard suffix on floating constant [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-standard suffix on floating constant [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-standard suffix on floating constant [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-standard suffix on floating constant [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-standard suffix on floating constant [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-standard suffix on floating constant [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-standard suffix on floating constant [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/numbers:223:1: error: non-standard suffix on floating constant [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/cstdlib:79:2: error: #include_next is a GCC extension .../libstdc++-v3/libsupc++/compare:844:45: error: ISO C++ does not support ‘__int128’ for ‘type name’ [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/cstddef:91:36: error: ISO C++ does not support ‘__int128’ for ‘type name’ [-Wpedantic] .../x86_64-pc-linux-gnu/libstdc++-v3/include/cstddef:93:45: error: ISO C++ does not support ‘__int128’ for ‘type name’ [-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 uses __extension__ before the template keyword of the specializations), for the __int128 cases perhaps too, no idea about #include_next though. Jakub