-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
<algorithm> / <numeric> / <xutility>: _ITERATOR_DEBUG_ARRAY_OVERLOADS should be removed #660
Comments
Is "quasi-conforming" code anything like "two-thirds pregnant" code? While I agree completely that we can and should remove these overloads that do nothing useful, I'm not sure where the bug is here. |
@CaseyCarter It's close enough to conforming that we did this whole escape hatch feature to keep it working in the past. |
My view is that the code is conforming, although yucky. According to the Standard, these algorithms take iterators by value, so arrays should decay to pointers. |
Where do we document this pointer arithmetic extension? https://docs.microsoft.com/en-us/cpp/cpp/arrays-cpp?view=vs-2019 talks about layout and addresses of array elements, but doesn't mention any such guarantees for pointer arithmetic. https://docs.microsoft.com/en-us/cpp/cpp/raw-pointers?view=vs-2019#pointer-arithmetic-and-arrays seems like the obvious place. Is https://godbolt.org/z/fDL3oM a bug? |
I do not believe it is an extension. It's going through array-to-pointer conversion twice. Post-Prague, array types are implicit lifetime types, so when the multidimensional array is created, I think http://eel.is/c++draft/intro.object#10 kicks in and says that there's implicitly a single dimensional array over the same space. |
I think as of Prague it is. |
Fascinating - I never realized that I think if we can get the compilers to agree that this is valid, then that provides sufficient justification for removing the IDAO overloads. |
I would be interested in that if you do not have other plans for it |
|
If you'd like to report bugs to MSVC (via Developer Community) and Clang/LLVM, that would be awesome. I believe we just need to hear from both compiler teams "yeah this is a bug" before removing the IDAO overloads; we don't actually need to block on getting compiler fixes. |
I don't believe any operation in the sample program is specified to implicitly create objects. Notably (I'm playing devil's advocate here, but I'm happy to be proven wrong.) |
FYI: P0593R6 clarifies that implicit creation of objects doesn't happen during constant evaluation so we need to be careful of using constexpr behavior to reason about runtime behavior in this space. |
If you get that pointer by going through array-to-pointer conversion it should be, no?
Want to put up the Richard Bat Signal? |
These examples don't implicitly create objects. But even if they did... a reference to type The things to remember about implicit object creation are that As a consequence, any local reasoning that was previously valid (in code that doesn't implicitly create objects) remains valid: there are no new starting states for that local reasoning, and no changes to what you can inductively determine. Implicit object creation only does things the programmer could have done explicitly. As an example of how that plays out, if you determined that your checks for passing a |
I try to reserve my Richard points for emergencies and/or blocking Clang bugs - thanks for the clarification, @zygoloid! |
Darn, on GitHub our collusion is exposed! :) |
I don't believe any such wording was actually applied. |
Hmm. From a conformance perspective, that means the IDAO overloads are neutral. From a complexity/throughput perspective, I agree with the rationale at the top of this issue for removing the IDAO overloads. Users who are especially concerned about safety should migrate to range algorithms, where we can always sense input and output bounds. |
The design intent is that implicit object creation need not be done during constant evaluation, but we were unable to find any way in which it would be observable -- mostly because casts between unrelated pointer types are disallowed -- so this didn't translate into any wording change. If there is a way to observe implicit object creation in constant evaluation, that's a wording bug that we should fix in the standard. One place where we get close to implicit object creation being observable in constant evaluation might be in |
So should this actually be removed or should it get some |
I think the consensus is that we should remove these overloads and ancillary test machinery as detailed in the first post. |
Fixes #660. Also move `_Array_(const_)?iterator` from `<xutility>` to `<array>`, since it's no longer needed by the IDAO.
Once upon a time, we used to warn users about passing pointers to STL algorithms for which iterator debugging could not analyze bounds / termination. This role of using STL algorithms for security-critical work has transitioned to the Guidelines Support Library, and as a result we removed such warnings from the STL some time ago.
A relic of that era though still exists in our nonstandard
_ITERATOR_DEBUG_ARRAY_OVERLOADS
which try to sniff out array bounds if the user happens to arrive with a built in array. For example:STL/stl/inc/algorithm
Lines 268 to 286 in 811c8c1
Unfortunately these reject quasi-conforming code like this (credit @StephanTLavavej):
Now that we no longer need these to suppress warnings, and these overloads have the potential to break customers, and they cost throughput and test time, they should now be removed. We should also remove explicit template arguments / identity_t / testing for ARRIT from https://github.com/microsoft/STL/blob/master/tests/std/include/instantiate_algorithms.hpp and other tests that might be testing array inputs to those algorithms expecting them to do something special. We should also remove any iterator debugging machinery (for example,
_STL_VERIFY_ARRAY_SIZE
) that exist in support of those overloads from<xutility>
if it they are no longer called.The text was updated successfully, but these errors were encountered: