Skip to content
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

Avoid stdext::checked_array_iterator for modern MSVC #1205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

StephanTLavavej
Copy link
Member

I work on MSVC's STL, and we'd like you to stop using one of our old non-Standard extensions, as we're working towards eventually removing it.

In VS 2005, MSVC's non-Standard extension stdext::checked_array_iterator was added to provide guaranteed bounds checking. At the same time, MSVC began emitting Microsoft "deprecation" warnings for using raw pointers as output iterators.

In VS 2017 15.8 (_MSC_VER 1915; see our handy decoder table), we stopped emitting those Microsoft "deprecation" warnings for using raw pointers as output iterators. Those warnings were incredibly annoying since they warned about perfectly correct, Standard-conforming code, and led users to generally disregard and silence such warnings. Also, the library was never the right place to implement them because of insufficient context. Instead, we began encouraging wider use of static analysis, which has sufficient context to emit better warnings about writing too many elements into a raw pointer. See our old blog post STL Features and Fixes in VS 2017 15.8 for more info. (This was internal MSVC-PR-120709.)

In VS 2022 17.8 (_MSC_VER 1938), we began emitting proper Microsoft deprecation warnings for the stdext::checked_array_iterator family, as this has been superseded not only by static analysis but also by C++20 std::span and downlevel-available gsl::span. ("Proper", in this case, because this is about actual Microsoft machinery.) These warnings were initially emitted for /std:c++17 and later, as a way to initially mitigate their impact while encouraging an ecosystem cleanup. (This was microsoft/STL#3818.)

In the upcoming VS 2022 17.11, we are unconditionally deprecating the stdext::checked_array_iterator family, as we're getting serious about eventual removal. (This was microsoft/STL#4605.)

In this PR, because Bond apparently supports compilers down to VS 2015, I'm refining the guard to use stdext::checked_array_iterator for MSVC older than VS 2017 15.8, where avoiding those "raw pointers as output iterators" warnings was necessary. For all recent MSVC versions, the portable (and still bounds-checked by your logic!) codepath is selected. In the long term, you may want to consider using C++20 std::span or taking a dependency on gsl::span, or similar changes (e.g. upgrading builtin arrays to std::arrays, etc.).

data-queue pushed a commit to microsoft/vcpkg that referenced this pull request Apr 30, 2024
…ater than or equal to 1915 (#38471)

`D:\b\bond\src\10.0.0-efd5420c47.clean\cpp\inc\bond\core\detail\sdl.h(29):
error C4996: 'stdext::checked_array_iterator<_Ptr>': warning STL4043:
stdext::checked_array_iterator, stdext::unchecked_array_iterator, and
related factory functions are non-Standard extensions and will be
removed in the future. std::span (since C++20) and gsl::span can be used
instead. You can define _SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING or
_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS to suppress this warning.`

The above problem occurred when I was testing an internal version of
msvc, and then I consulted Stephan T. Lavavej. He proposed a repair plan
and submitted PR [1205](microsoft/bond#1205)
upstream. I used stephan's repair plan to fix this problem in vcpkg.

- [X] Changes comply with the [maintainer
guide](https://github.com/microsoft/vcpkg-docs/blob/main/vcpkg/contributing/maintainer-guide.md).
- [ ] ~~SHA512s are updated for each updated download.~~
- [ ] ~~The "supports" clause reflects platforms that may be fixed by
this new version.~~
- [ ] ~~Any fixed [CI
baseline](https://github.com/microsoft/vcpkg/blob/master/scripts/ci.baseline.txt)
entries are removed from that file.~~
- [ ] ~~Any patches that are no longer applied are deleted from the
port's directory.~~
- [X] The version database is fixed by rerunning `./vcpkg x-add-version
--all` and committing the result.
- [X] Only one version is added to each modified port's versions file.

Compile test pass with following triplets:
```
x64-windows
```
yurybura pushed a commit to yurybura/vcpkg that referenced this pull request May 8, 2024
…ater than or equal to 1915 (microsoft#38471)

`D:\b\bond\src\10.0.0-efd5420c47.clean\cpp\inc\bond\core\detail\sdl.h(29):
error C4996: 'stdext::checked_array_iterator<_Ptr>': warning STL4043:
stdext::checked_array_iterator, stdext::unchecked_array_iterator, and
related factory functions are non-Standard extensions and will be
removed in the future. std::span (since C++20) and gsl::span can be used
instead. You can define _SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING or
_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS to suppress this warning.`

The above problem occurred when I was testing an internal version of
msvc, and then I consulted Stephan T. Lavavej. He proposed a repair plan
and submitted PR [1205](microsoft/bond#1205)
upstream. I used stephan's repair plan to fix this problem in vcpkg.

- [X] Changes comply with the [maintainer
guide](https://github.com/microsoft/vcpkg-docs/blob/main/vcpkg/contributing/maintainer-guide.md).
- [ ] ~~SHA512s are updated for each updated download.~~
- [ ] ~~The "supports" clause reflects platforms that may be fixed by
this new version.~~
- [ ] ~~Any fixed [CI
baseline](https://github.com/microsoft/vcpkg/blob/master/scripts/ci.baseline.txt)
entries are removed from that file.~~
- [ ] ~~Any patches that are no longer applied are deleted from the
port's directory.~~
- [X] The version database is fixed by rerunning `./vcpkg x-add-version
--all` and committing the result.
- [X] Only one version is added to each modified port's versions file.

Compile test pass with following triplets:
```
x64-windows
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant