1

The following MCVE gives a warning, using mingw-w64 4.9.2:

struct __declspec(dllimport) S
{
    int   foo() { return func(); }
    int   func();
    void  other_func();
};

inline int S::func() { return 1000; }

int main() {}

The warning is:

dt.cc:9:5: warning: 'int S::func()' redeclared without dllimport attribute
           after being referenced with dll linkage
inline int S::func() { return 1000; }
    ^

My question is: what is the problem being reported exactly, and should I do anything about it (e.g. file a bug report)?

The warning goes away if I change int func(); to inline int func(); -- not sure what the significance of this is.

Background: This pattern occurs in many places in the C++ library called POCO. The class has some functions whose bodies are in a DLL (e.g. other_func here) and some functions whose bodies occur in the header file (e.g. func here).

M.M
  • 138,810
  • 21
  • 208
  • 365
  • I would guess that as an `inline` function it's not exported by the DLL. – Cheers and hth. - Alf Mar 18 '15 at 00:50
  • @Cheersandhth.-Alf so are you saying I should just try to disable this warning or what? – M.M Mar 18 '15 at 00:53
  • I feel that such warnings must be there for some reason. So if I controlled the code I would either define the function in the class definition (or at the least declare it `inline` there), thus presumably not exporting it, or else replace the `inline` definition with a proper in the implementation file, for DLL export. Since you're not controlling the code but it's a widely used library perhaps just disable the warning for now, *and* report the issue. However, I don't see a warning name. How does one disable an unnamed g++ warning? – Cheers and hth. - Alf Mar 18 '15 at 02:23
  • Yeah I was wondering the same thing. One thing I'm not clear on (hence the question title) is whether the declspec in the class definition "propagates", i.e. do `foo`, `func` and `other_func` behave as if they also were `__declspec(dllimport)`, or does that explicitly have to be written into each function's declaration? The warning suggests that `func()` is treated as being `dllimport` up until the point where its definition appears (if the `foo` function is removed, the error goes away). – M.M Mar 18 '15 at 02:29
  • @Cheersandhth.-Alf actually I have found a duplicate – M.M Mar 18 '15 at 02:58

0 Answers0