C ++ std :: vector <bool> gives an uninitialized read error using drmemory
I use stl containers in my project and I found a strange error that I can not explain. Consider the following code:
#include <iostream> #include <vector> int main(int argc, char** argv) { std::vector<bool> vec; vec.resize(5, false); std::cout << vec.at(0); } This prints 0 as expected, but if I ran a memory check using drmemory, it detected an uninitialized read. Can anyone help in understanding this behavior?
Platform: win32; Compiler: mingw32 - gcc 4.7.2; Drmemory 1.6.0 - build 2
+6
1 answer
std::vector<bool> is a bizarre little thing that uses bits to achieve its goals. In this case, I would be pleased to assume that what you see is just a red herring.
As the saying goes, you might be better off with a different container , because this specialization pattern is universally despised .
+8