[cfe-dev] Inlining temporary destructors in the analyzer

Tim Toomay toomayt at toomaytech.com
Wed Aug 6 16:47:06 PDT 2014


On 8/6/2014 12:51 PM, cfe-dev-request at cs.uiuc.edu wrote:
> Hi Jordan,
> >>>>>>
> >>>>>>I made some progress on inlining temporary destructors. My main
> >>>>>>problem currently is that somehow the initializer values in my constructor
> >>>>>>get lost if I don't also reference 'this' via some other way.
> >>>>>>
> >>>>>>An examples shows that best. Consider:
> >>>>>>struct A {
> >>>>>>   A(int* y) : z(y) {}
> >>>>>>   ~A() { *z = 23; }
> >>>>>>   int *z;
> >>>>>>};
> >>>>>>void f() {
> >>>>>>   int x = 0;
> >>>>>>   {(A(&x));}
> >>>>>>}
> >>>>>>
> >>>>>>This leads to a "Dereference of undefined pointer value" warning on
> >>>>>>*z = 23.
> >>>>>>Funnily enough this warning goes away (and all values get correctly
> >>>>>>propagated) if change the constructor to be:
> >>>>>>A(int* y) : z(y) { (void)this; }
> >>>>>>

It sounds like Manuel is saying the warning is wrong.  The warning is actually quite helpful because the example code is unrealistic and the warning brings attention to that fact quite nicely.  Sorry if I am missing the boat :-) There is no guarantee the code won't crash on destruction of the object, so why worry about the initializer values?  It would help me understand what the problem is if the example made more sense.  Maybe like this:

struct A {
	A(int& y) : z(&y) {}
  	~A() { *z = 23; }
	int *z;
};

void f() {
int x = 0;
{(A(&x));}
}

Do the initializer values behave in this circumstance?

Cheers!
Tim





More information about the cfe-dev mailing list