The following code (reduced via creduce) gives a warning, when compiled with: g++ -std=c++11 -Os -Wall -Wno-invalid-offsetof -c dinit-warn.cc dinit-warn.cc:20:40: warning: 'void b::i< <template-parameter-1-1> >::dispatch(void*) [with <template-parameter-1-1> = {anonymous}::l]' declared 'static' but never defined [-Wunused-function] template <typename> class i : j { void dispatch(void *); }; ^~~~~~~~ However, the highlighted function, "dispatch", is not declared 'static' (and indeed nothing in the code is declared static). Occurs at -Os and -O2, -O3, not at -O1/-O0. --- begin --- class a; namespace b { template <typename> class i; class j { friend a; virtual void dispatch(void *); }; } class a { using d = b::j; public: template <typename e> using c = b::i<e>; void f() { d *k = nullptr; k->dispatch(this); } }; namespace b { template <typename> class i : j { void dispatch(void *); }; } using g = a; g h; namespace { class l : g::c<l> {}; } void m() { h.f(); } --- end ---
(Does not actually require -Wno-invalid-offsetof to reproduce; that was just me copying my command line literally. Problem first appears in GCC 6.1, not in 5.x, still present in 7.1).
Confirmed with GCC 8.0.
Reduced: struct j { virtual void dispatch(void *); }; template <typename> struct i : j { void dispatch(void *); }; namespace { struct l : i<l> {}; } void f(j *k) { k->dispatch(0); }
The warning started with r224161 Merge debug-early branch into mainline.