]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR libstdc++/84671 handle digit separators in duration literals
authorJonathan Wakely <jwakely@redhat.com>
Fri, 2 Mar 2018 20:38:50 +0000 (20:38 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 2 Mar 2018 20:38:50 +0000 (20:38 +0000)
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: r258157

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/parse_numbers.h
libstdc++-v3/testsuite/20_util/duration/literals/84671.cc [new file with mode: 0644]

index 05deec4f98e5b39a0c826a374e8b3a5aa513187d..e38def1b8507c11f9c0bea3959217a4456b0e787 100644 (file)
@@ -1,3 +1,11 @@
+2018-03-02  Jonathan Wakely  <jwakely@redhat.com>
+
+       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-27  Ville Voutilainen  <ville.voutilainen@gmail.com>
 
        Implement the missing bits of LWG 2769
index 51f1e42dddf26a93c174d5d8895afe35846cb57c..183f0e752e745e6b3f1bf85df8c68e9c2fab77e2 100644 (file)
@@ -197,10 +197,16 @@ namespace __parse_int
                    "integer literal does not fit in unsigned long long");
     };
 
-  template<unsigned _Base, unsigned long long _Pow, char _Dig>
-    struct _Number_help<_Base, _Pow, _Dig>
+  // Skip past digit separators:
+  template<unsigned _Base, unsigned long long _Pow, char _Dig, char..._Digs>
+    struct _Number_help<_Base, _Pow, '\'', _Dig, _Digs...>
+    : _Number_help<_Base, _Pow, _Dig, _Digs...>
+    { };
+
+  // Terminating case for recursion:
+  template<unsigned _Base, char _Dig>
+    struct _Number_help<_Base, 1ULL, _Dig>
     {
-      //static_assert(_Pow == 1U, "power should be one");
       using type = __ull_constant<_Digit<_Base, _Dig>::value>;
     };
 
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 (file)
index 0000000..4f50ec4
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do compile { target c++14 } }
+
+#include <chrono>
+
+// 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");