From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from avasout04.plus.net (avasout04.plus.net [212.159.14.19]) by sourceware.org (Postfix) with ESMTPS id 2E71D398753E for ; Sat, 19 Sep 2020 10:37:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2E71D398753E Received: from deneb ([80.229.24.9]) by smtp with ESMTP id JaFZkEBgFrXCcJaFak5Zos; Sat, 19 Sep 2020 11:37:51 +0100 X-Clacks-Overhead: "GNU Terry Pratchett" X-CM-Score: 0.00 X-CNFS-Analysis: v=2.3 cv=Q+xJH7+a c=1 sm=1 tr=0 a=E/9URZZQ5L3bK/voZ0g0HQ==:117 a=E/9URZZQ5L3bK/voZ0g0HQ==:17 a=reM5J-MqmosA:10 a=20KFwNOVAAAA:8 a=fXM4FEJ6vOjzBBum0QkA:9 a=CjuIK1q_8ugA:10 a=-An2I_7KAAAA:8 a=mDV3o1hIAAAA:8 a=Wd7Erw1rZoCISAI73doA:9 a=Sq34B_EcNBM9_nrAYB9S:22 a=_FVE-zBwftR9WsbkzFJk:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=jd6J4Gguk5HxikPWLKER:22 Received: from mac by deneb with local (Exim 4.92) (envelope-from ) id 1kJaFZ-0002PR-1q; Sat, 19 Sep 2020 11:37:49 +0100 Date: Sat, 19 Sep 2020 11:37:49 +0100 From: Mike Crowe To: Jonathan Wakely Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: libstdc++: Fix chrono::__detail::ceil to work with C++11 (was Re: [PATCH v5 6/8] libstdc++ atomic_futex: Avoid rounding errors in std::future::wait_* [PR91486]) Message-ID: <20200919103749.GA7523@mcrowe.com> References: <20200911144059.GU6061@redhat.com> <20200911172204.GV6061@redhat.com> <20200911185936.GW6061@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="/04w6evG8XlLl3ft" Content-Disposition: inline In-Reply-To: <20200911185936.GW6061@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CMAE-Envelope: MS4wfAJIV+DPKIv+J+8QMfo5ISL02CTkUsH2MfYWrokih8zbeBqAEyCqiprXbrE68I4woScL7y8famEquZfXIGGdFXvVcPFkcVJAxV8XLaYQ+orHy+xROi84 j4NTVqn13G29YvnX4tyjGOzGcpBjUkzdBGE= X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_CSS, URIBL_CSS_A autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Sep 2020 10:37:54 -0000 --/04w6evG8XlLl3ft Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Friday 11 September 2020 at 19:59:36 +0100, Jonathan Wakely wrote: > commit 53ad6b1979f4bd7121e977c4a44151b14d8a0147 > Author: Jonathan Wakely > Date: Fri Sep 11 19:59:11 2020 > > libstdc++: Fix chrono::__detail::ceil to work with C++11 > > In C++11 constexpr functions can only have a return statement, so we > need to fix __detail::ceil to make it valid in C++11. This can be done > by moving the comparison and increment into a new function, __ceil_impl, > and calling that with the result of the duration_cast. > > This would mean the standard C++17 std::chrono::ceil function would make > two further calls, which would add too much overhead when not inlined. > For C++17 and later use a using-declaration to add chrono::ceil to > namespace __detail. For C++11 and C++14 define chrono::__detail::__ceil > as a C++11-compatible constexpr function template. > > > libstdc++-v3/ChangeLog: > > * include/std/chrono [C++17] (chrono::__detail::ceil): Add > using declaration to make chrono::ceil available for internal > use with a consistent name. > (chrono::__detail::__ceil_impl): New function template. > (chrono::__detail::ceil): Use __ceil_impl to compare and > increment the value. Remove SFINAE constraint. This change introduces a new implementation of ceil that, as far as I can tell, has no tests. A patch is attached to add the equivalent of the existing chrono::ceil tests for chrono::__detail::ceil. The tests fail to compile if I run them without 53ad6b1979f4bd7121e977c4a44151b14d8a0147 as expected due to the previous non-C++11-compliant implementation. Mike. --/04w6evG8XlLl3ft Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-libstdc-Test-C-11-implementation-of-std-chrono-__det.patch" >From b9dffbf4f1bc05a887269ea95a3b86d5a611e720 Mon Sep 17 00:00:00 2001 From: Mike Crowe Date: Wed, 16 Sep 2020 15:31:28 +0100 Subject: [PATCH 1/2] libstdc++: Test C++11 implementation of std::chrono::__detail::ceil Commit 53ad6b1979f4bd7121e977c4a44151b14d8a0147 split the implementation of std::chrono::__detail::ceil so that when compiling for C++17 and later std::chrono::ceil is used but when compiling for earlier versions a separate implementation is used to comply with C++11's limited constexpr rules. Let's run the equivalent of the existing std::chrono::ceil test cases on std::chrono::__detail::ceil too to make sure that it doesn't get broken. libstdc++-v3/ChangeLog: * testsuite/20_util/duration_cast/rounding_c++11.cc: Copy rounding.cc and alter to support compilation for C++11 and to test std::chrono::__detail::ceil. --- .../20_util/duration_cast/rounding_c++11.cc | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 libstdc++-v3/testsuite/20_util/duration_cast/rounding_c++11.cc diff --git a/libstdc++-v3/testsuite/20_util/duration_cast/rounding_c++11.cc b/libstdc++-v3/testsuite/20_util/duration_cast/rounding_c++11.cc new file mode 100644 index 00000000000..f10d27fd082 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration_cast/rounding_c++11.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2016-2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++11" } +// { dg-do compile { target c++11 } } + +#include + +using std::chrono::seconds; +using std::chrono::milliseconds; + +using fp_seconds = std::chrono::duration; + +static_assert( std::chrono::__detail::ceil(milliseconds(1000)) + == seconds(1) ); +static_assert( std::chrono::__detail::ceil(milliseconds(1001)) + == seconds(2) ); +static_assert( std::chrono::__detail::ceil(milliseconds(1500)) + == seconds(2) ); +static_assert( std::chrono::__detail::ceil(milliseconds(1999)) + == seconds(2) ); +static_assert( std::chrono::__detail::ceil(milliseconds(2000)) + == seconds(2) ); +static_assert( std::chrono::__detail::ceil(milliseconds(2001)) + == seconds(3) ); +static_assert( std::chrono::__detail::ceil(milliseconds(2500)) + == seconds(3) ); +static_assert( std::chrono::__detail::ceil(milliseconds(500)) + == fp_seconds{0.5f} ); -- 2.28.0 --/04w6evG8XlLl3ft--