https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80916

            Bug ID: 80916
           Summary: Spurious "declared 'static' but never defined" warning
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: davmac at davmac dot org
  Target Milestone: ---

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 ---

Reply via email to