Fix narrowing conversions in string_view types
authorJonathan Wakely <jwakely@redhat.com>
Fri, 1 Dec 2017 16:10:31 +0000 (16:10 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 1 Dec 2017 16:10:31 +0000 (16:10 +0000)
* 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

libstdc++-v3/ChangeLog
libstdc++-v3/include/experimental/string_view
libstdc++-v3/include/std/string_view

index 14b65e3575ed2730e111f6398a30198a7a5cb583..601bc8a065d8f88f1b52c7473fbe424f6f3c415a 100644 (file)
@@ -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.
index 96d1f58f8e9ee265bd8290013803274ebcf00314..ef171ecc0255b85f701bbbc2196e31b09986dbe1 100644 (file)
@@ -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;
index 1266a07d04fac1b4ddde31255797deaf34cfd248..3b2901ab3c6fc90de19ba6b0522418a9ff39be0b 100644 (file)
@@ -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())