I have a tree stored in an array, and I'm trying to find a specific node:
std::vector<Node> nodes = ... const unsigned short sentinel = -1; unsigned short index = 0; for (Node* node = &nodes[index];
Nothing special, in other words. However, MSVC 2012 does not work with an attempt to access nodes[sentinel] , which is out of range. Turns out he first computes &nodes[index] , then checks index . (Debug mode, without optimization).
For me, it looks like a code generation error, but I have not seen such errors, at least for a decade. This is a simple non-optimized code. Of course, even with permutation, node is not actually used until index tested, and on x86 it is not very dangerous to have such a pointer outside the limits, but MSVC vector<> rightly claims that it is an illegal index.
Made a clean assembly and checked the assembly again; he repeats. The tree is also not empty, there is always a root node.
Am I forgetting something or is this really a serious compiler error?
c ++ visual-c ++
Msalters
source share