https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70834
frankhb1989 at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |frankhb1989 at gmail dot com
--- Comment #8 from frankhb1989 at gmail dot com ---
(In reply to Martin Sebor from comment #7)
> No change in GCC 11. This false positive too will be avoided by running
> -Wplacement-new later, when the program is in SSA form, rather than in the
> front end.
Actually worse in GCC 11. Try this case:
#include <cstddef>
#include <cstdlib>
#include <memory>
#include <new>
#include <stdexcept>
struct hdr_t
{
void* p_block;
};
constexpr auto offset = sizeof(hdr_t) > alignof(hdr_t) ? sizeof(hdr_t) :
alignof(hdr_t);
void* operator new(std::size_t bytes, std::size_t alignment)
{
auto space(offset + bytes + alignment);
auto ptr(static_cast<char*>(std::malloc(space)));
void* p(&ptr[offset]);
if(std::align(alignment, bytes, p, space))
{
(::new(static_cast<void*>(static_cast<char*>(p) - offset))
hdr_t)->p_block = ptr;
// (::new(ptr + (std::size_t(static_cast<char*>(p) - ptr)) -
offset) hdr_t)->p_block = ptr;
return p;
}
throw std::bad_alloc();
}
int main()
{}
This is warned in G++ 11.1, but not G++ 10.2.