[cfe-dev] C++ object lifetime checkers
Gabor Greif
gabor at mac.com
Sat Mar 3 16:36:10 PST 2012
Hi all,
here is a problem translated from what I encountered in work yesterday:
struct Foo {
const std::vector<int>& v;
Foo(const std::vector<int>& v) : v(v) {
// do some preflighting
}
~Foo(void)
{
// perform stuff
do_something_with(v);
}
};
void bar(int i)
{
Foo raii(std::vector<int>(1, i));
// more stuff
}
The big setback was that I had several bar-like functions that all
received a vector to start with, but this one only had a single
integer as input. So I passed that in a temporary vector. Hell broke
loose :-(
I wonder whether clang does catch this kind of problem (anyway the
Foo destructor is visible, inline), or whether it would be possible
to implement such an object lifetime check?
Cheers,
Gabor
More information about the cfe-dev
mailing list