From: Jonathan Wakely Date: Fri, 2 Mar 2018 23:52:06 +0000 (+0000) Subject: PR libstdc++/84671 handle digit separators in duration literals X-Git-Tag: releases/gcc-6.5.0~490 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc6e428fd1fcd7511e583952b3bd3656b468592e;p=thirdparty%2Fgcc.git PR libstdc++/84671 handle digit separators in duration literals Backport from mainline 2018-03-02 Jonathan Wakely PR libstdc++/84671 * include/bits/parse_numbers.h (_Number_help): Add partial specialization to handle digit separators. Adjust partial specialization for recursion temrination to require _Pow == 1ULL. * testsuite/20_util/duration/literals/84671.cc: New From-SVN: r258159 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4fa85fb1810e..79564c588976 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2018-03-02 Jonathan Wakely + + Backport from mainline + 2018-03-02 Jonathan Wakely + + PR libstdc++/84671 + * include/bits/parse_numbers.h (_Number_help): Add partial + specialization to handle digit separators. Adjust partial + specialization for recursion temrination to require _Pow == 1ULL. + * testsuite/20_util/duration/literals/84671.cc: New + 2018-02-19 Jonathan Wakely Backport from mainline diff --git a/libstdc++-v3/include/bits/parse_numbers.h b/libstdc++-v3/include/bits/parse_numbers.h index 7aa43fc2ba69..7823eb8ddf00 100644 --- a/libstdc++-v3/include/bits/parse_numbers.h +++ b/libstdc++-v3/include/bits/parse_numbers.h @@ -197,6 +197,13 @@ namespace __parse_int "integer literal does not fit in unsigned long long"); }; + // Skip past digit separators: + template + struct _Number_help<_Base, _Pow, '\'', _Dig, _Digs...> + : _Number_help<_Base, _Pow, _Dig, _Digs...> + { }; + + // Terminating case for recursion: template struct _Number_help<_Base, _Pow, _Dig> { diff --git a/libstdc++-v3/testsuite/20_util/duration/literals/84671.cc b/libstdc++-v3/testsuite/20_util/duration/literals/84671.cc new file mode 100644 index 000000000000..4f50ec4c9cc3 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/literals/84671.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2018 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-do compile { target c++14 } } + +#include + +// PR libstdc++/84671 +using namespace std::literals::chrono_literals; +constexpr auto ns_ok = 12113ns; +constexpr auto ns_fail = 12'11'3ns; +static_assert(ns_ok == ns_fail, "digit separators work in duration literals");