Why is this undefined behaviour?
- by xryl669
Here's the sample code:
X * makeX(int index) { return new X(index); }
struct Tmp {
mutable int count;
Tmp() : count(0) {}
const X ** getX() const {
static const X* x[] = { makeX(count++), makeX(count++) };
return x;
}
};
This reports Undefined Behaviour on CLang version 500 in the static array construction.
For sake of simplication for this post, the count is not static, but it does not change anything.