From patchwork Tue Aug 14 13:55:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 957525 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-483635-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="rceIwN41"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41qYyY2PXHz9s78 for ; Tue, 14 Aug 2018 23:55:31 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=MtyiHgvlR1oMgpvmbaFURbvBnPYLr/6qIwIm9t4XiZUC60bSTGT6U 3m56sAtb11MCudtjGIRNX3857ceo9VUi07blyp3Q7Zfn3iA8RDTaH9MGD9RTbNeH dCdikGfTZY7zrrnHI7o00zDEwcbvt535fd8t84sQu3gnTDdo9FhJ20= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=uTqKOQxn4/isEg5TkNnSktbMPSU=; b=rceIwN41SkGsl9CfTp+6 L/r3hoH1sFStJnsQD36fctKmVo7wqtdO++VOVVrqmzk5UxqQ0PeqxsVYCZSu9Zxx MNfP4WqFb6EeFBqIQL2NWFi5spY5Ba2794+BmXPU/8EcFUyrlIpoH4dpQcxuVO82 j5alBdWKeA5oytwLK35/kaQ= Received: (qmail 69397 invoked by alias); 14 Aug 2018 13:55:22 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 69243 invoked by uid 89); 14 Aug 2018 13:55:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=ratio X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 14 Aug 2018 13:55:20 +0000 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94CA3307C944; Tue, 14 Aug 2018 13:55:19 +0000 (UTC) Received: from localhost (ovpn-117-178.phx2.redhat.com [10.3.117.178]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43B371062241; Tue, 14 Aug 2018 13:55:19 +0000 (UTC) Date: Tue, 14 Aug 2018 14:55:17 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Simplify overflow checks in duration literals Message-ID: <20180814135517.GA5649@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.2 (2017-12-15) * include/std/chrono (__check_overflow): Simplify definition. (_Checked_integral_constant): Remove. Tested x86_64-linux, committed to trunk. commit c0dec9d05de4695136694f78f2f76e3c9f15b3f1 Author: Jonathan Wakely Date: Tue Aug 14 14:33:38 2018 +0100 Simplify overflow checks in duration literals * include/std/chrono (__check_overflow): Simplify definition. (_Checked_integral_constant): Remove. diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index da03fdccce4..871c896144a 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -900,24 +900,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wliteral-suffix" - template - struct _Checked_integral_constant - : integral_constant<_Rep, static_cast<_Rep>(_Val)> - { - static_assert(_Checked_integral_constant::value >= 0 - && _Checked_integral_constant::value == _Val, - "literal value cannot be represented by duration type"); - }; - template constexpr _Dur __check_overflow() { using _Val = __parse_int::_Parse_int<_Digits...>; - using _Rep = typename _Dur::rep; - // TODO: should be simply integral_constant<_Rep, _Val::value> - // but GCC doesn't reject narrowing conversions to _Rep. - using _CheckedVal = _Checked_integral_constant<_Rep, _Val::value>; - return _Dur{_CheckedVal::value}; + constexpr typename _Dur::rep __repval = _Val::value; + static_assert(__repval >= 0 && __repval == _Val::value, + "literal value cannot be represented by duration type"); + return _Dur(__repval); } constexpr chrono::duration>