<div dir="ltr">Hi All,<div><br></div><div>It seems that the clang static analyzer does not correctly handle C++ constructors. For example, I have the following code:</div><div><br></div><div><div>struct S {</div><div><span class="" style="white-space:pre">      </span>S(int x, int y, int z) {</div><div><span class="" style="white-space:pre">           </span>a = x;</div><div><span class="" style="white-space:pre">             </span>b = y;</div><div><span class="" style="white-space:pre">             </span>c = z;</div><div><span class="" style="white-space:pre">     </span>}</div><div><span class="" style="white-space:pre">  </span>int a;</div><div><span class="" style="white-space:pre">     </span>int b;</div><div><span class="" style="white-space:pre">     </span>int c;</div><div>};</div><div><br></div><div>void objectCreate() {</div><div><span class="" style="white-space:pre">       </span>S *newS = new S(12, 0, 15);</div><div><span class="" style="white-space:pre">        </span>if (newS->b)</div><div><span class="" style="white-space:pre">            </span>newS->c++;</div><div><span class="" style="white-space:pre">      </span>else</div><div><span class="" style="white-space:pre">               </span>newS->a++;</div><div><span class="" style="white-space:pre">      </span>delete newS;</div><div>}</div></div><div><br></div><div>Since newS->b initializes to 0, the expression "newS->a++" should never execute. However, the analyzer in fact generates two new states and evaluates both branches. If I replace the newS->b condition with the integer literal 0, then only the first branch is evaluated, as I would expect. I dug into this further, and found that newS's constructor is called AFTER objectCreate() has been evaluated. In other words, newS's constructor is called after "delete newS". This is clearly the wrong behavior.</div><div><br></div><div>This is not the first time I have observed C++ constructors being handled incorrectly. I also posted several weeks ago with the same observation regarding implicit copy constructors.</div><div><br></div><div>Any help would be so very appreciated, as this has been driving me crazy!</div><div><br></div><div>~Scott Constable</div></div>