<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, May 19, 2015 at 2:19 PM, Nick Lewycky <span dir="ltr"><<a href="mailto:nlewycky@google.com" target="_blank">nlewycky@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On 18 May 2015 at 12:59, Ismail Pazarbasi <span dir="ltr"><<a href="mailto:ismail.pazarbasi@gmail.com" target="_blank">ismail.pazarbasi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: ismailp<br>
Date: Mon May 18 14:59:11 2015<br>
New Revision: 237608<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=237608&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=237608&view=rev</a><br>
Log:<br>
Detect uses of mismatching forms of 'new' and 'delete'<br>
<br>
Emit warning when operand to `delete` is allocated with `new[]` or<br>
operand to `delete[]` is allocated with `new`.<br>
<br>
rev 2 update:<br>
`getNewExprFromInitListOrExpr` should return `dyn_cast_or_null`<br>
instead of `dyn_cast`, since `E` might be null.<br></blockquote><div><br></div></span>FYI, I'm getting an assertion firing:<div><br></div><div><div>clang: llvm/tools/clang/lib/Sema/SemaExprCXX.cpp:2447: const clang::CXXNewExpr *(anonymous namespace)::MismatchingNewDeleteDetector::getNewExprFromInitListOrExpr(const clang::Expr *): Assertion `E != nullptr && "Expected a valid initializer expression"' failed.</div><div><br></div><div>on presumed to be valid code (code that builds with a previous version of clang). I'm creduce'ing a testcase now.</div></div><div><div class="h5"><div><br></div></div></div></div></div></div></blockquote><div><br></div><div>Try this reduced case:</div><div><br></div><div>template <typename T></div><div>struct Base {</div><div>  struct S {</div><div>    const T *t = 0;</div><div>  };</div><div>};</div><div><br></div><div>void Foo(Base<double>::S s) { delete s.t; }</div><div><br></div><div>I think what is happening is that the warning is looking for the initializer of Base<double>::S::t, which is never used and not instantiated.  So, the FieldDecl reports that it has an initializer, but returns a null pointer when trying to retrieve it.</div></div></div></div>