[Bug libstdc++/84671] New: Chrono literals don't accept apostrophe as separator
curdeius at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Mar 2 12:40:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84671
Bug ID: 84671
Summary: Chrono literals don't accept apostrophe as separator
Product: gcc
Version: 8.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: curdeius at gmail dot com
Target Milestone: ---
Created attachment 43547
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43547&action=edit
bug-chrono-literals-apostrophe-repro
Concerned GCC versions: from 5.0.0 onwards (tested up to GCC 8.0.1 trunk from
2018-02-28).
GCC 4.9.3 accepts the code.
Online demo: http://coliru.stacked-crooked.com/a/eed5e2702d1daaa8.
When using UDLs from std::literals::chrono_literals, rejects the use of
apostrophes as delimiters.
E.g.:
```
using namespace std::literals::chrono_literals;
auto ns_ok = 12113ns;
auto ns_fail = 12'113ns;
```
Compiling this code (or precisely the attachment) using `g++ prog.cc
-std=c++14` or any standard from C++14 onwards gives the message:
```
In file included from /opt/wandbox/gcc-head/include/c++/8.0.1/chrono:42,
from prog.cc:1:
/opt/wandbox/gcc-head/include/c++/8.0.1/bits/parse_numbers.h: In instantiation
of 'struct std::__parse_int::_Number_help<10, 100, '\'', '1', '1', '3'>':
/opt/wandbox/gcc-head/include/c++/8.0.1/bits/parse_numbers.h:195:57:
recursively required from 'struct std::__parse_int::_Number_help<10, 1000, '2',
'\'', '1', '1', '3'>'
/opt/wandbox/gcc-head/include/c++/8.0.1/bits/parse_numbers.h:195:57: required
from 'struct std::__parse_int::_Number_help<10, 10000, '1', '2', '\'', '1',
'1', '3'>'
/opt/wandbox/gcc-head/include/c++/8.0.1/bits/parse_numbers.h:208:12: required
from 'struct std::__parse_int::_Number<10, '1', '2', '\'', '1', '1', '3'>'
/opt/wandbox/gcc-head/include/c++/8.0.1/bits/parse_numbers.h:248:12: required
from 'struct std::__parse_int::_Parse_int<'1', '2', '\'', '1', '1', '3'>'
/opt/wandbox/gcc-head/include/c++/8.0.1/chrono:905:67: required from
'constexpr _Dur std::literals::chrono_literals::__check_overflow() [with _Dur =
std::chrono::duration<long int, std::ratio<1, 1000000000> >; char ..._Digits =
{'1', '2', '\'', '1', '1', '3'}]'
/opt/wandbox/gcc-head/include/c++/8.0.1/chrono:961:65: required from
'constexpr std::chrono::nanoseconds
std::literals::chrono_literals::operator""ns() [with char ..._Digits = {'1',
'2', '\'', '1', '1', '3'}; std::chrono::nanoseconds =
std::chrono::duration<long int, std::ratio<1, 1000000000> >]'
prog.cc:5:16: required from here
/opt/wandbox/gcc-head/include/c++/8.0.1/bits/parse_numbers.h:196:42: error:
static assertion failed: integer literal does not fit in unsigned long long
static_assert((type::value / _Pow) == __digit::value,
~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
```
The problem seems to come from struct _Number_help that does not take
apostrophes '\'' into account
(https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/parse_numbers.h#L188).
More information about the Gcc-bugs
mailing list