[PATCH, libstdc++/61166] overflow when parse number in std::duration operator""
Jonathan Wakely
jwakely@redhat.com
Fri May 16 11:09:00 GMT 2014
On 15/05/14 22:54 -0400, Ed Smith-Rowland wrote:
>On 05/15/2014 03:03 PM, Jonathan Wakely wrote:
>>Here's a finished patch to simplify <bits/parse_numbers.h>
>>
>>Tested x86_64-linux. Ed, any objection to this version?
>>
>This looks great, thanks!
I committed that to trunk, I'll put it on the 4.9 branch too.
>Having done that should we actually stop using it as suggested in the
>bug trail? ;-)
I was going to do that, then realised that there's a defect in the
standard where it requires overflow in duration integer literals to be
diagnosed. That's only possible with literal operator templates, so I
think we should keep your _Parse_int code, but apply the attached
change to detect overflow.
As the TODO comment says, it should be sufficient to simply
instantiate integral_constant<_Rep, _Val::value> to give a diagnostic
when _Rep{_Value::value} is narrowing, but GCC only gives a warning
for it, and that's suppressed in a system header, so I do an explicit
static_assert. That could be replaced with ...
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Woverflow"
#pragma GCC diagnostic error "-Wsystem-headers"
template<typename _Dur, char... _Digits>
constexpr _Dur __check_overflow()
{
using _Val = __parse_int::_Parse_int<_Digits...>;
using _Rep = typename _Dur::rep;
return _Dur{integral_constant<_Rep, _Val::value>::value};
}
#pragma GCC diagnostic pop
... but I have plans to do that sort of thing more widely, which I'll
deal with another time as part of https://gcc.gnu.org/PR50871 and/or
https://gcc.gnu.org/PR58876 (what do other people think about using
diagnostic pragmas to locally re-enable diagnostics in our headers?)
Tested x86_64-linux, committed to trunk.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 7717 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20140516/c0a2efc8/attachment.bin>
More information about the Libstdc++
mailing list