diff mbox series

[committed] libstdc++: Fix warning regressions in <bits/stl_tempbuf.h>

Message ID 20240619130954.1695641-1-jwakely@redhat.com
State New
Headers show
Series [committed] libstdc++: Fix warning regressions in <bits/stl_tempbuf.h> | expand

Commit Message

Jonathan Wakely June 19, 2024, 1:08 p.m. UTC
Tested x86_64-linux. Pushed to trunk.

-- >8 --

I caused some new warnings with -Wsystem-headers with my recent changes
to std::get_temporary_buffer and std::_Temporary_buffer. There's a
-Wsign-compare warning which can be avoided by casting the ptrdiff_t
argument to size_t (which also conveniently rejects negative values).

There's also a -Wdeprecated-declarations warning because I moved where
std::get_temporary_buffer is called, but didn't move the diagnostic
pragmas that suppress the warning for calling it.

libstdc++-v3/ChangeLog:

	* include/bits/stl_tempbuf.h (__get_temporary_buffer): Cast
	argument to size_t to handle negative values and suppress
	-Wsign-compare warning.
	(_Temporary_buffer): Move diagnostic pragmas to new location of
	call to std::get_temporary_buffer.
---
 libstdc++-v3/include/bits/stl_tempbuf.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libstdc++-v3/include/bits/stl_tempbuf.h b/libstdc++-v3/include/bits/stl_tempbuf.h
index fa03fd27704..759c4937744 100644
--- a/libstdc++-v3/include/bits/stl_tempbuf.h
+++ b/libstdc++-v3/include/bits/stl_tempbuf.h
@@ -82,7 +82,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       inline _Tp*
       __get_temporary_buffer(ptrdiff_t __len) _GLIBCXX_NOTHROW
       {
-	if (__builtin_expect(__len > (size_t(-1) / sizeof(_Tp)), 0))
+	if (__builtin_expect(size_t(__len) > (size_t(-1) / sizeof(_Tp)), 0))
 	  return 0;
 
 #if __cpp_aligned_new
@@ -200,6 +200,8 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       size_type  _M_original_len;
       struct _Impl
       {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 	explicit
 	_Impl(ptrdiff_t __original_len)
 	{
@@ -208,6 +210,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  _M_len = __p.second;
 	  _M_buffer = __p.first;
 	}
+#pragma GCC diagnostic pop
 
 	~_Impl()
 	{ std::__detail::__return_temporary_buffer(_M_buffer, _M_len); }
@@ -315,8 +318,6 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  __ucr(__first, __last, __seed);
     }
 
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
   template<typename _ForwardIterator, typename _Tp>
     _Temporary_buffer<_ForwardIterator, _Tp>::
     _Temporary_buffer(_ForwardIterator __seed, size_type __original_len)
@@ -324,7 +325,6 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       std::__uninitialized_construct_buf(begin(), end(), __seed);
     }
-#pragma GCC diagnostic pop
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace