https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82760
Bug ID: 82760 Summary: Incorrect code generated for aligned new Product: gcc Version: 7.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jarek at jpelczar dot com Target Milestone: --- Created attachment 42493 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42493&action=edit Source code, temps, It seems that the following type of code creates memory overwrite condition. When I compile code with -std=c++17. Compiling code with c++11 seems to be fine. It turns out that the returned pointer by operator new with std::align_val_t is fine, but GCC will move the final pointer by 0x40, so this will cause overwriting of the next allocation. struct aligned_foo { char x[2048]; ~aligned_foo(); aligned_foo() { memset(x, 0, sizeof(x)); } } __attribute__((aligned(64))); aligned_foo * gFoo; void test(int count) { gFoo = new(std::nothrow) aligned_foo[count]; } int main() { test(2); return 0; } aligned_foo::~aligned_foo() { }