[cfe-dev] C++ object lifetime checkers
Tom Care
tom.care at uqconnect.edu.au
Sun Mar 4 02:57:56 PST 2012
Hi Gabor,
The short answer is not right now as the analyzer's C++ support is not quite there. The support to enable these kind of checks is being worked on though. There are a few ways we could find this kind of error.
We are always interested to hear about real-world bugs that you would like to be detected, and I encourage you to file bugs with an example of what you would like to be found (like the example you included :))
Tom
I'm always interested in hearing about
On 04/03/2012, at 1:36 AM, Gabor Greif wrote:
> 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
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
More information about the cfe-dev
mailing list