-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Getting a weak-vtables warning with clang on ubuntu 22.04 #4087
Comments
I am facing the same issue (my project has to have -Wweak-vtables enabled), and it seems like a low effort to fix it? std::exception has a virtual destructor, which is the reason for this warning. All that is needed is to declare an explicit destructor in each of the exception classes and add out-of-line default definitions like "exception::~exception() = default;" alongside. |
Indeed we compile with |
Ok, I'm getting to the boundaries of my C++ knowledge. I can fix the ~exception() override; to the class definition and add exception::~exception() = default; outside the class. This makes Clang happy, but Clang-Tidy complains:
I am note sure how to fix this, because the library is header-only. Furthermore, GCC complains (
I guess this can be fixed by just adding a copy constructor and a copy assignment operator. |
I think maybe you should add |
Oh, yeah, if there wasn't a destructor there before and you add one, it suppresses the other of the special 5. |
Okay, I've done some reading and some thinking, and I don't think it's possible to fix this in a header-only library. I mean that we MIGHT be able to silence the warning, but it will still result in the exact same behavior everywhere. There is no implementation file where we can define any virtual function. All the virtual functions will still be defined in every translation unit that includes the header. On the other hand, we already have a diagnostic push/pop, so maybe just add it here and document that since it isn't possible to honor the spirit of the warning in a header-only library, we just disable it: json/include/nlohmann/detail/macro_scope.hpp Line 160 in 64f68dc
|
I added a diagnostic push to suppress the warning in #4500. PTAL. |
* 🔧 remove warning suppression * 🚨 fix weak-vtables warning #4087 * 🚨 suppress -Wweak-vtables warning * 🚨 suppress -Wweak-vtables warning * ✅ fix test * ✅ fix test * ✅ fix test
* 🔧 remove warning suppression * 🚨 fix weak-vtables warning nlohmann#4087 * 🚨 suppress -Wweak-vtables warning * 🚨 suppress -Wweak-vtables warning * ✅ fix test * ✅ fix test * ✅ fix test
Description
I noticed that when ever I try to compile with clang ( 11 - 15 as I have installed) on with my normal warning flags on linux then I always ends up with a warning from the exceptions header about weak-vtables, I do know that some would say I have alot of warning flags activated but that is because that is what I saw some time ago that fmtlib uses and chose to use it myself also to catch errors and posible bad practices from my side
I do use CPM-cmake to pull in libraries purely because that is able to store them in a local cache so I don't have to pull the libraries over and over for each project and it does use the github release
Reproduction steps
Tested with clang 11, 12, 13, 14, 15 on ubuntu jammy (22.04)
The shell command is taken from cmake log
I'm using CPM-cmake to pull in libraries and in essence its just pulling the 3.11.2 release from the release tab by tag
Error messages
Compiler and operating system
Clang 11, 12, 13, 14, 15 on ubuntu 22.04
Library version
3.11.2
Validation
develop
branch is used.The text was updated successfully, but these errors were encountered: