Reputation: 5676
Something incredibly convenient happens when running this code in debug mode:
std::array<int, 2> test;
test[5] = 123;
When I hit the "Retry" button on the assert message box, Visual Studio 2015 will show the test[5] = 123;
line. And I have no idea why it is not breaking at the assert location inside the operator instead.
Does anybody have an explanation for that? Is there a way I can replicate the same behavior in my own code?
edit:
To make it clear, the Visual Studio STL does bounds checking for operator[]
in Debug mode (_ITERATOR_DEBUG_LEVEL), and I am running in Debug mode. The question here is why it breaks at this location and not inside the operator where the assert is actually triggered.
Also notice that with Visual Studio 2013 it breaks inside the operator, so there is a difference in behavior between 2015 and 2013, the plot thickens.
Upvotes: 1
Views: 287
Reputation: 283684
For Visual Studio 2015, the process by which the debugger determines which functions are not "My Code" and customization is documented:
You can specify modules, source files, and functions to treat as non-user code in call stacks by specifying them in
*.natjmc
files.
Upvotes: 3