Bug 80916 - [7/8/9 Regression] Spurious "declared 'static' but never defined" warning
Summary: [7/8/9 Regression] Spurious "declared 'static' but never defined" warning
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2017-05-30 00:46 UTC by Davin McCall
Modified: 2018-08-31 12:08 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 5.5.0
Known to fail: 6.4.0, 7.2.0, 8.2.0, 9.0
Last reconfirmed: 2018-08-31 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Davin McCall 2017-05-30 00:46:36 UTC
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 ---
Comment 1 Davin McCall 2017-05-30 23:43:16 UTC
(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).
Comment 2 Martin Sebor 2017-11-27 20:23:13 UTC
Confirmed with GCC 8.0.
Comment 3 ensadc 2018-08-31 05:44:17 UTC
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);
}
Comment 4 Jonathan Wakely 2018-08-31 12:08:13 UTC
The warning started with r224161

    Merge debug-early branch into mainline.