From patchwork Mon Jun 23 11:32:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 362763 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3C92D14007C for ; Mon, 23 Jun 2014 21:32:57 +1000 (EST) 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=ysbF7+VZjPOh2nQjX89zOFWf8tPhFnQAouU+YXCWlndpniP9K8Ysh DZzNxXX1rF+cg/kQKZoh8CrObCFGO6UMCU+w091aejzmglxFQNZRNqxvRaMgn23P 82goFr+Hfm8HzQEL9mW73KBCraXubIBZzSLbZIbn7z5wQBFS+sRjI8= 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=wkytC0TqaKwCJOleHJugC63pYqo=; b=ZI0o2zCvYpCLRCCrCYUV oT9H9DO3/8KbkWsyEjHy+ZpMK8AjNXC58bvh7f3kcrHDnl3riv+Fjk0xwaWODAt8 5MSmKvTshf3dM5XOWMMNrqTEAO/4s596MBPeE0Bq+NdFfBCWTINGJ57UtDq+DwFR /HemHxY8pSKl6aheImep2RU= Received: (qmail 2026 invoked by alias); 23 Jun 2014 11:32:40 -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 1998 invoked by uid 89); 23 Jun 2014 11:32:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 23 Jun 2014 11:32:07 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5NBW6ZO022291 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Jun 2014 07:32:06 -0400 Received: from localhost (vpn1-7-131.ams2.redhat.com [10.36.7.131]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5NBW5fn030275; Mon, 23 Jun 2014 07:32:06 -0400 Date: Mon, 23 Jun 2014 12:32:05 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [patch] fix std::chrono::duration literals Message-ID: <20140623113205.GA7313@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) This fixes errors when using 0s or 1'000s to create durations. Tested x86_64-linux, committed to trunk. commit c57e645222ac9bf476ef5b6414773b5f4e2b86fc Author: Jonathan Wakely Date: Sun Jun 22 18:06:42 2014 +0100 * include/bits/parse_numbers.h (_Number_help): Fix divide-by-zero. * include/std/chrono (_Checked_integral_constant): Allow zero. * testsuite/20_util/duration/literals/values.cc: Test non-positive values and digit separators. diff --git a/libstdc++-v3/include/bits/parse_numbers.h b/libstdc++-v3/include/bits/parse_numbers.h index a29d127..f46c59c 100644 --- a/libstdc++-v3/include/bits/parse_numbers.h +++ b/libstdc++-v3/include/bits/parse_numbers.h @@ -190,10 +190,11 @@ namespace __parse_int using __digit = _Digit<_Base, _Dig>; using __valid_digit = typename __digit::__valid; using __next = _Number_help<_Base, - _Pow / (_Base * __valid_digit::value), + __valid_digit::value ? _Pow / _Base : _Pow, _Digs...>; using type = __ull_constant<_Pow * __digit::value + __next::type::value>; - static_assert((type::value / _Pow) == __digit::value, "overflow"); + static_assert((type::value / _Pow) == __digit::value, + "integer literal does not fit in unsigned long long"); }; template @@ -214,7 +215,6 @@ namespace __parse_int { }; //------------------------------------------------------------------------------ -// This _Parse_int is the same 'level' as the old _Base_dispatch. template struct _Parse_int; diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index 39ad5e3..88eaa16 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -791,7 +791,7 @@ _GLIBCXX_END_NAMESPACE_VERSION struct _Checked_integral_constant : integral_constant<_Rep, static_cast<_Rep>(_Val)> { - static_assert(_Checked_integral_constant::value > 0 + static_assert(_Checked_integral_constant::value >= 0 && _Checked_integral_constant::value == _Val, "literal value cannot be represented by duration type"); }; diff --git a/libstdc++-v3/testsuite/20_util/duration/literals/values.cc b/libstdc++-v3/testsuite/20_util/duration/literals/values.cc index f55c32f..ce86358 100644 --- a/libstdc++-v3/testsuite/20_util/duration/literals/values.cc +++ b/libstdc++-v3/testsuite/20_util/duration/literals/values.cc @@ -56,6 +56,12 @@ test03() VERIFY( workday == std::chrono::hours(8) ); auto fworkday = 8.0h; VERIFY( (fworkday == std::chrono::duration>(8.0L)) ); + auto immediate = 0s; + VERIFY( immediate == std::chrono::seconds(0) ); + auto minute_ago = -1min; + VERIFY( minute_ago == std::chrono::minutes(-1) ); + auto separated = 1'000'000s; + VERIFY( separated == std::chrono::seconds(1'000'000) ); } int