https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99851
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Status|UNCONFIRMED |NEW CC| |msebor at gcc dot gnu.org Last reconfirmed| |2021-03-31 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- Confirmed, thanks! Just to make sure I understand: we want a warning for the operator new declaration (irrespective of its definition) because the nothrow_t argument suggests it doesn't throw but the absence of noexcept implies it might. I.e., the warning can be emitted as early as in the C++ front end. The following modified test case shows that the the null test in main() is eliminated on the basis of the missing noexcept: $ cat pr99851.C && g++ -O1 -S -Wall -fdump-tree-optimized=/dev/stdout pr99851.C namespace std { typedef __SIZE_TYPE__ size_t; const struct nothrow_t { } nothrow; } struct X { void* operator new[](std::size_t n, const std::nothrow_t&) { return __builtin_malloc (n); } unsigned data = 0; }; int main() { void *p = new (std::nothrow) X[2]; if (!p) __builtin_abort (); __builtin_printf ("%p\n", p); } ;; Function main (main, funcdef_no=1, decl_uid=2393, cgraph_uid=5, symbol_order=5) (executed once) int main () { void * _9; <bb 2> [local count: 357878154]: _9 = __builtin_malloc (8); MEM[(struct X *)_9].data = 0; MEM[(struct X *)_9 + 4B].data = 0; __builtin_printf ("%p\n", _9); return 0; }