Conversation

frederick-vs-ja

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.

Fixes #1768.

@robert-andrzejuk

This should use std::span.

@lederernc

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

@barcharcraz Can you review this?

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 and it works for us.

@pochtmeister

Is it possible to merge this into main?

@lederernc

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 files in conan for our team were to modify containerstream.h, producerconsumerstream.h and rawptrstream.h as per this 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

If it's helpful I can supply an alternate PR with this in it. just let me know.

Sign up for free to join this conversation on . Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

stdext::checked_array_iterator compilation error with VS 2022 17.8 Preview 2