Hi, when trying to analyse dynamically allocated objects in C++, I came across the need to identify results of the new operator (at least the non-overridden standard one) as malloc-allocated. The cleanest approach would probably be to mark the new operator function with the malloc attribute. So I did that (see the extra-short patch below), bootstrapped c and c++ on i686-linux (with "all,fold" checking) and ran the test suite. To my surprise, there were no new regressions.
I am now wondering why the function is not marked as malloc already. In fact, its implementation always returns what it gets from the built-in malloc. Are there any known issues or concerns with this that the test suite cannot reveal? Can anyone comment on this? Moreover, just before sending this email, I have found out that there is already PR23383 (builtin array operator new is not marked with malloc attribute) about the array variant of the new operator. Given its implementation, it is probably the same thing... Thank you very much in advance, Martin Index: libstdc++-v3/libsupc++/new =================================================================== --- libstdc++-v3/libsupc++/new (revision 128207) +++ libstdc++-v3/libsupc++/new (working copy) @@ -92,7 +92,8 @@ * Placement new and delete signatures (take a memory address argument, * does nothing) may not be replaced by a user's program. */ -void* operator new(std::size_t) throw (std::bad_alloc); +void* operator new(std::size_t) throw (std::bad_alloc) + __attribute__ ((malloc)); void* operator new[](std::size_t) throw (std::bad_alloc); void operator delete(void*) throw(); void operator delete[](void*) throw();