Apple's gcc 4.2 has a warning flag called -Wglobal-constructors that they describe in their invoke.texi like this: @c APPLE LOCAL begin Wglobal-constructors 6324584 @item -Wglobal-constructors @opindex Wglobal-constructors Warn about namespace scope data that requires construction or destruction, or functions that use the constructor attribute or the destructor attribute. Additionally warn if the Objective-C GNU runtime is used to initialize various metadata. @c APPLE LOCAL end Wglobal-constructors 6324584 In their c.opt it says: ; APPLE LOCAL begin Wglobal-constructors 6324584 Wglobal-constructors C ObjC C++ ObjC++ Var(warn_global_constructors) Warn when global (namespace scope) objects require runtime construction or destruction or when functions that use attribute constructor or destructor are used. This is useful to help maintain fast program startup and end times. ; APPLE LOCAL end Wglobal-constructors 6324584 Apparently this option has been carried forward to clang, as pointed out in bug 71456. It would be useful for FSF GCC to have this warning option, too.
Confirmed.
Patch: https://gcc.gnu.org/ml/gcc-patches/2019-05/msg01860.html
(In reply to Marek Polacek from comment #2) > Patch: https://gcc.gnu.org/ml/gcc-patches/2019-05/msg01860.html Does Sean have a bugzilla account?
(In reply to Eric Gallager from comment #3) > (In reply to Marek Polacek from comment #2) > > Patch: https://gcc.gnu.org/ml/gcc-patches/2019-05/msg01860.html > > Does Sean have a bugzilla account? I don't see it. Probably not yet.
Still wanted. In llvm-project, compiler-rt is using -Wglobal-constructors. llvm/lib/Support will use it as well.