Commit ad8fda29 by Jonathan Wakely Committed by Jonathan Wakely

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
parent f03858e5
2017-12-01 Jonathan Wakely <jwakely@redhat.com> 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 * include/bits/basic_string.h (operator""s): Add pragmas to disable
-Wliteral-suffix warnings. -Wliteral-suffix warnings.
* include/experimental/string_view (operator""sv): Likewise. * include/experimental/string_view (operator""sv): Likewise.
......
...@@ -422,11 +422,11 @@ inline namespace fundamentals_v1 ...@@ -422,11 +422,11 @@ inline namespace fundamentals_v1
static constexpr int static constexpr int
_S_compare(size_type __n1, size_type __n2) noexcept _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() ? 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() ? std::numeric_limits<int>::min()
: static_cast<int>(difference_type{__n1 - __n2}); : static_cast<int>(difference_type(__n1 - __n2));
} }
size_t _M_len; size_t _M_len;
......
...@@ -408,7 +408,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -408,7 +408,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static constexpr int static constexpr int
_S_compare(size_type __n1, size_type __n2) noexcept _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()) if (__diff > std::numeric_limits<int>::max())
return std::numeric_limits<int>::max(); return std::numeric_limits<int>::max();
if (__diff < std::numeric_limits<int>::min()) if (__diff < std::numeric_limits<int>::min())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment