-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix the deprecation warning of stdext::checked_array_iterator
#1769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the deprecation warning of stdext::checked_array_iterator
#1769
Conversation
This should use std::span.
lederernc
commented
Dec 5, 2023
This should use
std::span.
It looks like the rest of the code base is targeting something much older than C++20.
I think this is fine as is.
kobykahane
commented
Jan 8, 2024
@barcharcraz Can you review this?
@lederernc
lederernc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been testing this internally in a conan recipe applying this patch and it works for us.
pochtmeister
commented
Jan 17, 2025
Is it possible to merge this into main?
I recently had to address this when some of our devs upgraded to MSVC 17.12.x and this solution was no longer a workable solution for us.
The solution I ended up deploying with patch files in conan for our team were to modify containerstream.h, producerconsumerstream.h and rawptrstream.h as per this patch file:
diff --git a/Release/include/cpprest/containerstream.h b/Release/include/cpprest/containerstream.h
index 6e949a75..cebd01e6 100644
--- a/Release/include/cpprest/containerstream.h
+++ b/Release/include/cpprest/containerstream.h
@@ -399,7 +399,7 @@ private:
auto readBegin = std::begin(m_data) + m_current_position;
auto readEnd = std::begin(m_data) + newPos;
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
// Avoid warning C4996: Use checked iterators under SECURE_SCL
std::copy(readBegin, readEnd, stdext::checked_array_iterator<_CharType*>(ptr, count));
#else
diff --git a/Release/include/cpprest/producerconsumerstream.h b/Release/include/cpprest/producerconsumerstream.h
index 3487c460..fc1f2e74 100644
--- a/Release/include/cpprest/producerconsumerstream.h
+++ b/Release/include/cpprest/producerconsumerstream.h
@@ -439,7 +439,7 @@ private:
_CharType* beg = rbegin();
_CharType* end = rbegin() + countRead;
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
// Avoid warning C4996: Use checked iterators under SECURE_SCL
std::copy(beg, end, stdext::checked_array_iterator<_CharType*>(dest, count));
#else
@@ -462,7 +462,7 @@ private:
const _CharType* srcEnd = src + countWritten;
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
// Avoid warning C4996: Use checked iterators under SECURE_SCL
std::copy(src, srcEnd, stdext::checked_array_iterator<_CharType*>(wbegin(), static_cast<size_t>(avail)));
#else
diff --git a/Release/include/cpprest/rawptrstream.h b/Release/include/cpprest/rawptrstream.h
index 1f15ecbe..ed2384d4 100644
--- a/Release/include/cpprest/rawptrstream.h
+++ b/Release/include/cpprest/rawptrstream.h
@@ -439,7 +439,7 @@ private:
auto readBegin = m_data + m_current_position;
auto readEnd = m_data + newPos;
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
// Avoid warning C4996: Use checked iterators under SECURE_SCL
std::copy(readBegin, readEnd, stdext::checked_array_iterator<_CharType*>(ptr, count));
#else
@@ -466,7 +466,7 @@ private:
if (newSize > m_size) throw std::runtime_error("Writing past the end of the buffer");
// Copy the data
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
// Avoid warning C4996: Use checked iterators under SECURE_SCL
std::copy(ptr, ptr + count, stdext::checked_array_iterator<_CharType*>(m_data, m_size, m_current_position));
#else
lederernc
commented
Jan 18, 2025
If it's helpful I can supply an alternate PR with this patch in it. just let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stdext::checked_iterator_iterator is being removed now.
frederick-vs-ja
commented
Nov 2, 2025
Perhaps the should be abandoned as @StephanTLavavej said the strategy creating a copy was incorrect. Opened #1836 instead.
Uh oh!
There was an error while loading. Please reload this page.
By adding a non-deprecated copy of
checked_array_iterator.The implementation heavily relies on the implementation details of MSVC STL, but IMO this is OK since we only use it when
defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0.(Attempted to fix) #1768.