In most cases when debugging, if I have a vector (in Xcode 9), I am shown a list of indices representing the values in the vector.
Desired
Other times, I get this unhelpful representation:
Undesired
I am unable to figure out what conditions cause LLDB to display vectors in the undesirable way.
Question
What is causing the undesired behavior? Can it be fixed without re-writing the code? Is this a bug in LLDB?
Here is a short code example that reproduces the undesired behavior:
#include <iostream>
#include <vector>
std::vector<int> createVector()
{
std::vector<int> v = { 1, 2, 3 };
return v;
}
int main(int argc, const char * argv[])
{
const auto& v = createVector();
std::cout << v.front() << std::endl;
return 0;
}
Here is a link to the Xcode project:
http://s000.tinyupload.com/?file_id=21020556485232357417
This is a known bug in how the std::vector data summary & formatters work for reference variables. Note that in the expr v
the expression parser actually considers v to be a straight vector, not a reference to a vector... That's why that printing works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With