https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91343
Bug ID: 91343 Summary: Spurious strict-aliasing warning with template class inheritance. Product: gcc Version: 9.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: a-yee at u dot northwestern.edu Target Milestone: --- The following code leads to a strict-aliasing warning. But there is no aliasing here. https://godbolt.org/z/m2P_4- Possibly Related or Duplicate: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89960 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81152 #include <iostream> using namespace std; struct Parent{ int data = 0; }; template <typename Context> class Child : public Parent{ public: static int func(){ Child tp; int x = tp.data; return x; } }; template class Child<int>; int main(){ } <source>: In static member function 'static int Child<Context>::func()': <source>:13:17: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 13 | int x = tp.data; | ^~ ASM generation compiler returned: 0 <source>: In static member function 'static int Child<Context>::func()': <source>:13:17: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 13 | int x = tp.data; | ^~