Consider the following program
struct X
{
int d;
X(){} // forget to initialize d
};
int main()
{
X x;
volatile int y=x.d; // read uninitialized d
(void)y; // (kill useless warning)
}
Clearly it has undefined behavior, which I'd like in general to be able to catch using some debugging tool. I've tried cppcheck (using their online demo) and g++ -fsanitize=address
as well as g++ -fsanitize=undefined
, and valgrind
. But these tools don't report me that x.d
is uninitialized when read.
What tools can I use to catch these sorts of undefined behavior (preferably running on Linux)?