https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81145
Bug ID: 81145 Summary: bogus "dereferencing type-punned pointer will break strict-aliasing rules" diagnostic with incomplete class type Product: gcc Version: 7.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: richard-gccbugzilla at metafoo dot co.uk Target Milestone: --- Testcase: struct B { int n; }; struct A #ifndef BUG { B b; } #endif ; extern A a; int n = reinterpret_cast<B*>(&a)->n; This produces a bogus "dereferencing type-punned pointer will break strict-aliasing rules" diagnostic with -DBUG, but correctly suppresses the warning when the definition of A is visible. Note that under C++ P0137R1 / DR1776, the A object is pointer-interconvertible with its b member, so the reinterpret_cast produces a usable pointer to a.b, regardless of whether the definition of A is visible. Perhaps GCC's TBAA should be less aggressive when comparing an incomplete type against (at least) a standard-layout type?