_Orphan_range crash when using static vector (another example of)

Viewed 526

For DEBUG builds in MS Visual Studio 2019, Ver. 16.10.0, Toolset v142, I got with the code below an exception: 'read access violation' in _Orphan_range_unlocked() (possibly very similar to what is discussed here [1])

The problem does not occur for in older VS versions, in release builds or by using clang toolset. However, because the crash only occurs in these very specific circumstances, I suspect there may be a bug in Visual Studio. Or is it a programming error after all? I would like to understand this.

#include <vector>
#include <array>

int main()
{
    // Exception: 'read access violation' in _Orphan_range_unlocked()
    // (in C++20 MSVC Debug builds but not in C++17 nor Release)

    static std::array<std::vector<int>, 4> arrvec;
    arrvec[0].reserve(3);
    arrvec[0].emplace_back(1);  // <- Exception occurs here
}

[1]: https://stackoverflow.com/a/62605686/15157143)

For this I opened a bug report here: https://github.com/microsoft/STL/issues/1934

0 Answers
Related