Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
frederick-vs-ja wants to merge 2 commits into microsoft:master
base: master
Choose a base branch
Loading
from frederick-vs-ja:checked-array-iterator

Conversation

@frederick-vs-ja
Copy link

@frederick-vs-ja frederick-vs-ja commented Sep 20, 2023
edited
Loading

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.

Copy link
Contributor

robert-andrzejuk commented Nov 24, 2023
edited
Loading

This should use std::span.

Copy link

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.

robert-andrzejuk and frederick-vs-ja reacted with thumbs up emoji

Copy link

@barcharcraz Can you review this?

Copy link

@lederernc lederernc left a 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.

Copy link

Is it possible to merge this into main?

Copy link

lederernc commented Jan 18, 2025
edited
Loading

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

Copy link

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

* =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
*
* This file defines the checked iterator iterator template that originated from MSVC STL's
* stdext::checked_iterator_iterator, which is now deprecated.
Copy link
Author

@frederick-vs-ja frederick-vs-ja Oct 31, 2025
edited
Loading

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.

Copy link
Author

Perhaps the should be abandoned as @StephanTLavavej said the strategy creating a copy was incorrect. Opened #1836 instead.

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

Reviewers

1 more reviewer

@lederernc lederernc lederernc approved these changes

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /