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

-Wglobal-constructors is silenced for derived classes with a virtual base destructor in c++2b mode #121004

Open
apache-hb opened this issue Dec 23, 2024 · 1 comment
Labels
c++23 clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@apache-hb
Copy link

When a class that contains a non trivial member inherits from a pure virtual base class that has an explicitly declared virtual destructor in c++2b mode -Wglobal-constructors is not raised, but an entry is still added to the .init_array to initialize the objects vtable before main. This behaviour is not present in c++20 mode. The entry is only added at -O0, at -O2 and higher __cxx_global_var_init is elided and the vtable is placed directly in the data section which makes this very hard to track down.

Godbolt reproducer link: https://godbolt.org/z/W355314dK

@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer c++26 and removed new issue labels Dec 23, 2024
@frederick-vs-ja
Copy link
Contributor

Before C++23 (P2448R2) the program is ill-formed, no diagnostic required, and Clang rejects it in old modes for that reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++23 clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

No branches or pull requests

3 participants