This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix -Wsystem-header warnings in libstdc++
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Fri, 1 Dec 2017 16:10:22 +0000
- Subject: Re: [PATCH] Fix -Wsystem-header warnings in libstdc++
- Authentication-results: sourceware.org; auth=none
- References: <20171201151156.GW31922@redhat.com>
On 01/12/17 15:11 +0000, Jonathan Wakely wrote:
This fixes a number of warnings that show up with -Wsystem-headers
This fixes some more.
Tested powerpc64le-linux, committed to trunk.
commit cea830828177721a6d201dd6c201c34235626641
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Dec 1 15:59:01 2017 +0000
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.
diff --git a/libstdc++-v3/include/experimental/string_view b/libstdc++-v3/include/experimental/string_view
index 96d1f58f8e9..ef171ecc025 100644
--- a/libstdc++-v3/include/experimental/string_view
+++ b/libstdc++-v3/include/experimental/string_view
@@ -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;
diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view
index 1266a07d04f..3b2901ab3c6 100644
--- a/libstdc++-v3/include/std/string_view
+++ b/libstdc++-v3/include/std/string_view
@@ -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())
commit b992ef59e17964034ffb6dd094629468998ee6e9
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Nov 30 16:26:22 2017 +0000
Disable -Wliteral-suffix for standard UDLs
* include/bits/basic_string.h (operator""s): Add pragmas to disable
-Wliteral-suffix warnings.
* include/experimental/string_view (operator""sv): Likewise.
* include/std/chrono (operator""h, operator""min, operator""s)
(operator""ms, operator""us, operator""ns): Likewise.
* include/std/complex (operator""if, operator""i, operator""il):
Likewise.
* include/std/string_view (operator""sv): Likewise.
* testsuite/20_util/duration/literals/range.cc: Adjust dg-error.
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index a4b81137571..70373e7448a 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -6665,6 +6665,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
inline namespace string_literals
{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wliteral-suffix"
_GLIBCXX_DEFAULT_ABI_TAG
inline basic_string<char>
operator""s(const char* __str, size_t __len)
@@ -6689,6 +6691,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return basic_string<char32_t>{__str, __len}; }
#endif
+#pragma GCC diagnostic pop
} // inline namespace string_literals
} // inline namespace literals
diff --git a/libstdc++-v3/include/experimental/string_view b/libstdc++-v3/include/experimental/string_view
index 8eaf9ec3d96..96d1f58f8e9 100644
--- a/libstdc++-v3/include/experimental/string_view
+++ b/libstdc++-v3/include/experimental/string_view
@@ -644,6 +644,8 @@ namespace experimental
{
inline namespace string_view_literals
{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wliteral-suffix"
inline constexpr basic_string_view<char>
operator""sv(const char* __str, size_t __len) noexcept
{ return basic_string_view<char>{__str, __len}; }
@@ -663,6 +665,7 @@ namespace experimental
operator""sv(const char32_t* __str, size_t __len) noexcept
{ return basic_string_view<char32_t>{__str, __len}; }
#endif
+#pragma GCC diagnostic pop
} // namespace string_literals
} // namespace literals
} // namespace experimental
diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index 9491508e637..2419e82acce 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -884,6 +884,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
inline namespace chrono_literals
{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wliteral-suffix"
template<typename _Rep, unsigned long long _Val>
struct _Checked_integral_constant
: integral_constant<_Rep, static_cast<_Rep>(_Val)>
@@ -958,6 +960,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator""ns()
{ return __check_overflow<chrono::nanoseconds, _Digits...>(); }
+#pragma GCC diagnostic pop
} // inline namespace chrono_literals
} // inline namespace literals
@@ -966,7 +969,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
using namespace literals::chrono_literals;
} // namespace chrono
-#endif // __cplusplus > 201103L
+#endif // C++14
// @} group chrono
diff --git a/libstdc++-v3/include/std/complex b/libstdc++-v3/include/std/complex
index bd8b09d84f0..61f8cc1fce3 100644
--- a/libstdc++-v3/include/std/complex
+++ b/libstdc++-v3/include/std/complex
@@ -1941,6 +1941,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline namespace literals {
inline namespace complex_literals {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wliteral-suffix"
#define __cpp_lib_complex_udls 201309
constexpr std::complex<float>
@@ -1967,6 +1969,7 @@ inline namespace complex_literals {
operator""il(unsigned long long __num)
{ return std::complex<long double>{0.0L, static_cast<long double>(__num)}; }
+#pragma GCC diagnostic pop
} // inline namespace complex_literals
} // inline namespace literals
diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view
index 68b4b08f8f4..1266a07d04f 100644
--- a/libstdc++-v3/include/std/string_view
+++ b/libstdc++-v3/include/std/string_view
@@ -626,6 +626,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
inline namespace string_view_literals
{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wliteral-suffix"
inline constexpr basic_string_view<char>
operator""sv(const char* __str, size_t __len) noexcept
{ return basic_string_view<char>{__str, __len}; }
@@ -645,6 +647,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator""sv(const char32_t* __str, size_t __len) noexcept
{ return basic_string_view<char32_t>{__str, __len}; }
#endif
+#pragma GCC diagnostic pop
} // namespace string_literals
} // namespace literals
diff --git a/libstdc++-v3/testsuite/20_util/duration/literals/range.cc b/libstdc++-v3/testsuite/20_util/duration/literals/range.cc
index c0d1a6e5885..20d82c5cdbe 100644
--- a/libstdc++-v3/testsuite/20_util/duration/literals/range.cc
+++ b/libstdc++-v3/testsuite/20_util/duration/literals/range.cc
@@ -26,6 +26,6 @@ test01()
// std::numeric_limits<int64_t>::max() == 9223372036854775807;
auto h = 9223372036854775808h;
- // { dg-error "cannot be represented" "" { target *-*-* } 892 }
+ // { dg-error "cannot be represented" "" { target *-*-* } 894 }
}
// { dg-prune-output "in constexpr expansion" } // needed for -O0