Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning C4275: non dll-interface class used as base for dll-interface class #84

Closed
dalboris opened this issue Aug 5, 2019 · 3 comments

Comments

@dalboris
Copy link
Contributor

dalboris commented Aug 5, 2019

When compiling on Windows, we have hundreds of such warnings.

We should either silence it, or, preferably if possible, fix the code so that there are no warnings.

@dalboris dalboris added the eng label Aug 5, 2019
@dalboris
Copy link
Contributor Author

Note: there is a nice write-up here of possible options to solve this problem:

https://stackoverflow.com/questions/24511376/how-to-dllexport-a-class-derived-from-stdruntime-error

@dalboris
Copy link
Contributor Author

dalboris commented Mar 6, 2020

The solution I was planning for fixing this was to not export exception classes (i.e, they wouldn't be declared with VGC_FOO_API), and have them fully inline, as suggested in the above SO answer.

However, Clang isn't happy about that. If the class if fully inline, then Clang warns us about the lack of out-of-line virtual method definition, see #24 . But worse than just a warning, I can see that inheritance doesn't work properly. I tested to not use VGC_GRAPHICS_API for vgc::graphics::FontError, and have it fully inline. Then, I intentionally thrown an exception to see what happens (see first commit in: #373)

In Windows and Linux, in the test_font.py test, I get the expected behavior, that is, Python informs us that a vgc.graphics.FontError was thrown and not caught:

https://ci.appveyor.com/project/vgc/vgc/builds/31276308
https://travis-ci.org/vgc/vgc/jobs/658880589?utm_medium=notification&utm_source=github_status

Traceback (most recent call last):
    File "C:/dev/vgc/libs/vgc/graphics/tests/test_font.py", line 28, in testConstructor
      library = FontLibrary()
  vgc.graphics.FontError: no error

However, in macOS with Clang, I get:

https://travis-ci.org/vgc/vgc/jobs/658880590?utm_medium=notification&utm_source=github_status

Traceback (most recent call last):
  File "/Users/travis/build/vgc/vgc/libs/vgc/graphics/tests/test_font.py", line 28, in testConstructor
    library = FontLibrary()
vgc.core.RuntimeError: no error

Notice how Python doesn't recognize the derived exception type. This does look like a potential problem with the vtable, as Clang warns us.

I don't really know what's the proper solution to make both MSVC and Clang happy. Perhaps the exception classes should be inline-not-exported on MSVC, and exported-non-inline on GCC and Clang, which we could implement via some macros, e.g., VGC_GRAPHICS_API_EXCEPTION, and VGC_CORE_DECLARE_EXCEPTION_DESTRUCTOR / DEFINE, which expand to different things on MSVC vs. other compilers.

I couldn't find good examples of what other libraries do. Many don't use exceptions at all (e.g., Google).

@dalboris
Copy link
Contributor Author

dalboris commented Mar 6, 2020

See also: pybind/pybind11#1769

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant