<div dir="ltr">Strictly speaking, a <a href="https://en.cppreference.com/w/cpp/language/delete">delete expression's syntax</a> is the following:<div>::(optional)    delete    expression<br>::(optional)    delete [] expression<br></div><div>So, in the second case `<span style="font-family:monospace">fundamental_nothrow`</span>, you do not have any delete expression in the AST, because the code syntactically does not contain any. Instead what you do is that you explicitly call a function, that happens to be the `operator delete` function, so you actually have a call expression rather than a delete expression.</div><div><br></div><div>Hope this helps,</div><div>Gabor</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 2, 2020 at 4:43 PM Kristóf Umann <<a href="mailto:dkszelethus@gmail.com">dkszelethus@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi!<div><br></div><div>I noticed that for using "regular" operator delete, the CXXDeleteExpr is present, and so is CXXNewExpr, but when using the nothrow version, and it is causing me a headache while trying to implement a deallocator event in the clang static analyzer. I have the following declaratations:<br><font face="monospace"><br></font></div><div><font face="monospace">namespace std {<br>typedef __typeof__(sizeof(int)) size_t;<br>struct nothrow_t {};<br>extern const nothrow_t nothrow;<br>} // namespace std<br><br>void* operator new(std::size_t, const std::nothrow_t&) throw();<br>void* operator new[](std::size_t, const std::nothrow_t&) throw();<br>void operator delete(void*, const std::nothrow_t&) throw();<br>void operator delete[](void*, const std::nothrow_t&) throw();<br><br>void* operator new (std::size_t size, void* ptr) throw() { return ptr; };<br>void* operator new[] (std::size_t size, void* ptr) throw() { return ptr; };<br>void operator delete (void* ptr, void*) throw() {};<br>void operator delete[] (void* ptr, void*) throw() {};</font><br></div><div><br></div><div>In the first code example, the "regular", non-nothrow version is used:</div><div><font face="monospace"><br>namespace fundamental {<br>void f() {<br>  int *p = new int;<br>  delete p;<br>}<br>} // namespace fundamental<br><br>namespace fundamental_array {<br>void f() {<br>  int *p = new int[2];<br>  delete[] p;<br>}<br>} // namespace fundamental_array</font><br></div><div><br></div><div>|-NamespaceDecl 0x1e568e0 </home/szelethus/Documents/llvm-project/clang/test/Analysis/operator-delete-analysis-order.cpp:14:1, line:19:1> line:14:11 fundamental<br>| `-FunctionDecl 0x1e56970 <line:15:1, line:18:1> line:15:6 f 'void ()'<br>|   `-CompoundStmt 0x1e56b50 <col:10, line:18:1><br>|     |-DeclStmt 0x1e56ae0 <line:16:3, col:19><br>|     | `-VarDecl 0x1e56a28 <col:3, col:16> col:8 used p 'int *' cinit<br>|     |   `-CXXNewExpr 0x1e56aa8 <col:12, col:16> 'int *' Function 0x1e25a20 'operator new' 'void *(unsigned long)'<br>|     `-CXXDeleteExpr 0x1e56b30 <line:17:3, col:10> 'void' Function 0x1e25e00 'operator delete' 'void (void *) noexcept'<br>|       `-ImplicitCastExpr 0x1e56b18 <col:10> 'int *' <LValueToRValue><br>|         `-DeclRefExpr 0x1e56af8 <col:10> 'int *' lvalue Var 0x1e56a28 'p' 'int *'<br>|-NamespaceDecl 0x1e56b70 <line:21:1, line:26:1> line:21:11 fundamental_array<br>| `-FunctionDecl 0x1e56c00 <line:22:1, line:25:1> line:22:6 f 'void ()'<br>|   `-CompoundStmt 0x1e56e58 <col:10, line:25:1><br>|     |-DeclStmt 0x1e56de8 <line:23:3, col:22><br>|     | `-VarDecl 0x1e56cb8 <col:3, col:21> col:8 used p 'int *' cinit<br>|     |   `-CXXNewExpr 0x1e56da8 <col:12, col:21> 'int *' array Function 0x1e25be0 'operator new[]' 'void *(unsigned long)'<br>|     |     `-ImplicitCastExpr 0x1e56d58 <col:20> 'unsigned long' <IntegralCast><br>|     |       `-IntegerLiteral 0x1e56d20 <col:20> 'int' 2<br>|     `-CXXDeleteExpr 0x1e56e38 <line:24:3, col:12> 'void' array Function 0x1e25f68 'operator delete[]' 'void (void *) noexcept'<br>|       `-ImplicitCastExpr 0x1e56e20 <col:12> 'int *' <LValueToRValue><br>|         `-DeclRefExpr 0x1e56e00 <col:12> 'int *' lvalue Var 0x1e56cb8 'p' 'int *'<br></div><div><br></div><div>In the second, the nothrow version. Observe how CXXNewExpr is still present, but not CXXDeleteExpr.</div><div><br></div><div><font face="monospace">namespace fundamental_nothrow {<br>void f() {<br>  int *s = new (std::nothrow) int;<br>  operator delete(s, std::nothrow);<br>}<br>} // namespace nontrivial_destructor<br><br>namespace fundamental_array_nothrow {<br>void f() {<br>  int *s = new (std::nothrow) int;<br>  operator delete(s, std::nothrow);<br>}<br>} // namespace nontrivial_destructor</font><br><br></div><div>|-NamespaceDecl 0x1e59b88 <line:54:1, line:60:1> line:54:11 fundamental_nothrow<br>| `-FunctionDecl 0x1e59c18 <line:56:1, line:59:1> line:56:6 f 'void ()'<br>|   `-CompoundStmt 0x1e5a020 <col:10, line:59:1><br>|     |-DeclStmt 0x1e59e48 <line:57:3, col:34><br>|     | `-VarDecl 0x1e59cd0 <col:3, col:31> col:8 used s 'int *' cinit<br>|     |   `-CXXNewExpr 0x1e59e08 <col:12, col:31> 'int *' Function 0x1e49a08 'operator new' 'void *(std::size_t, const std::nothrow_t &) throw()'<br>|     |     `-DeclRefExpr 0x1e59d88 <col:17, col:22> 'const std::nothrow_t' lvalue Var 0x1e26360 'nothrow' 'const std::nothrow_t'<br>|     `-CallExpr 0x1e59fc0 <line:58:3, col:34> 'void'<br>|       |-ImplicitCastExpr 0x1e59fa8 <col:3, col:12> 'void (*)(void *, const std::nothrow_t &) throw()' <FunctionToPointerDecay><br>|       | `-DeclRefExpr 0x1e59f28 <col:3, col:12> 'void (void *, const std::nothrow_t &) throw()' lvalue Function 0x1e49fe0 'operator delete' 'void (void *, const std::nothrow_t &) throw()'<br>|       |-ImplicitCastExpr 0x1e5a008 <col:19> 'void *' <BitCast><br>|       | `-ImplicitCastExpr 0x1e59ff0 <col:19> 'int *' <LValueToRValue><br>|       |   `-DeclRefExpr 0x1e59eb8 <col:19> 'int *' lvalue Var 0x1e59cd0 's' 'int *'<br>|       `-DeclRefExpr 0x1e59ef8 <col:22, col:27> 'const std::nothrow_t' lvalue Var 0x1e26360 'nothrow' 'const std::nothrow_t'<br>`-NamespaceDecl 0x1e5a040 <line:62:1, line:68:1> line:62:11 fundamental_array_nothrow<br>  `-FunctionDecl 0x1e5a0d0 <line:64:1, line:67:1> line:64:6 f 'void ()'<br>    `-CompoundStmt 0x1e5a440 <col:10, line:67:1><br>      |-DeclStmt 0x1e5a2c8 <line:65:3, col:34><br>      | `-VarDecl 0x1e5a188 <col:3, col:31> col:8 used s 'int *' cinit<br>      |   `-CXXNewExpr 0x1e5a288 <col:12, col:31> 'int *' Function 0x1e49a08 'operator new' 'void *(std::size_t, const std::nothrow_t &) throw()'<br>      |     `-DeclRefExpr 0x1e5a240 <col:17, col:22> 'const std::nothrow_t' lvalue Var 0x1e26360 'nothrow' 'const std::nothrow_t'<br>      `-CallExpr 0x1e5a3e0 <line:66:3, col:34> 'void'<br>        |-ImplicitCastExpr 0x1e5a3c8 <col:3, col:12> 'void (*)(void *, const std::nothrow_t &) throw()' <FunctionToPointerDecay><br>        | `-DeclRefExpr 0x1e5a3a8 <col:3, col:12> 'void (void *, const std::nothrow_t &) throw()' lvalue Function 0x1e49fe0 'operator delete' 'void (void *, const std::nothrow_t &) throw()'<br>        |-ImplicitCastExpr 0x1e5a428 <col:19> 'void *' <BitCast><br>        | `-ImplicitCastExpr 0x1e5a410 <col:19> 'int *' <LValueToRValue><br>        |   `-DeclRefExpr 0x1e5a338 <col:19> 'int *' lvalue Var 0x1e5a188 's' 'int *'<br>        `-DeclRefExpr 0x1e5a378 <col:22, col:27> 'const std::nothrow_t' lvalue Var 0x1e26360 'nothrow' 'const std::nothrow_t'<br></div><div><br></div><div>Is this intended? If so, why?</div><div><br></div><div>Cheers,</div><div>Husi</div></div>
</blockquote></div>