Fix narrowing conversions in string_view types
* include/experimental/string_view (basic_string_view::_S_compare): Use value-init so narrowing conversions are not ill-formed. * include/std/string_view (basic_string_view::_S_compare): Likewise. From-SVN: r255321
This commit is contained in:
parent
f03858e51d
commit
ad8fda29e6
3 changed files with 8 additions and 4 deletions
|
@ -1,5 +1,9 @@
|
|||
2017-12-01 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
* include/experimental/string_view (basic_string_view::_S_compare):
|
||||
Use value-init so narrowing conversions are not ill-formed.
|
||||
* include/std/string_view (basic_string_view::_S_compare): Likewise.
|
||||
|
||||
* include/bits/basic_string.h (operator""s): Add pragmas to disable
|
||||
-Wliteral-suffix warnings.
|
||||
* include/experimental/string_view (operator""sv): Likewise.
|
||||
|
|
|
@ -422,11 +422,11 @@ inline namespace fundamentals_v1
|
|||
static constexpr int
|
||||
_S_compare(size_type __n1, size_type __n2) noexcept
|
||||
{
|
||||
return difference_type{__n1 - __n2} > std::numeric_limits<int>::max()
|
||||
return difference_type(__n1 - __n2) > std::numeric_limits<int>::max()
|
||||
? std::numeric_limits<int>::max()
|
||||
: difference_type{__n1 - __n2} < std::numeric_limits<int>::min()
|
||||
: difference_type(__n1 - __n2) < std::numeric_limits<int>::min()
|
||||
? std::numeric_limits<int>::min()
|
||||
: static_cast<int>(difference_type{__n1 - __n2});
|
||||
: static_cast<int>(difference_type(__n1 - __n2));
|
||||
}
|
||||
|
||||
size_t _M_len;
|
||||
|
|
|
@ -408,7 +408,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
static constexpr int
|
||||
_S_compare(size_type __n1, size_type __n2) noexcept
|
||||
{
|
||||
const difference_type __diff{__n1 - __n2};
|
||||
const difference_type __diff = __n1 - __n2;
|
||||
if (__diff > std::numeric_limits<int>::max())
|
||||
return std::numeric_limits<int>::max();
|
||||
if (__diff < std::numeric_limits<int>::min())
|
||||
|
|
Loading…
Add table
Reference in a new issue