https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67875
Bug ID: 67875 Summary: missing -Warray-bounds in a default placement new expression, bogus location on an overload Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- GCC fails to diagnose placement new expressions that attempt to access an array past its bounds and that involve the default placement operator new: $ cat t.cpp && g++ -c -O2 -Wall -std=gnu++11 t.cpp #include <new> struct A { char a [4]; } a; void foo () { new (&a.a [5]) char; } $ When the out-of-bounds access involves a user-defined overload of the placement new operator that makes use of the out-of-bounds pointer, GCC issues an -Warray-bounds warning that points into the body of the operator instead of the new expression. (Clang diagnoses both cases correctly.) $ cat t.cpp && g++ -c -O2 -Wall -std=gnu++11 t.cpp typedef __typeof__ (sizeof 0) size_t; extern "C" int printf (const char*, ...); void* operator new (size_t n, void *p, int) { printf ("%s: %zu, %p\n", __PRETTY_FUNCTION__, n, p); return p; } struct A { char a [4]; } a; void foo () { new (&a.a [5], 0) char; } t.cpp: In function ‘void foo()’: t.cpp:6:56: warning: array subscript is above array bounds [-Warray-bounds] printf ("%s: %zu, %p\n", __PRETTY_FUNCTION__, n, p); ^