[clang] [Clang] Make '-Wglobal-constructors` work on the GNU attributes (PR #129917)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 6 09:50:00 PST 2025


================
@@ -2138,6 +2138,8 @@ static void handleConstructorAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   if (AL.getNumArgs() &&
       !S.checkUInt32Argument(AL, AL.getArgAsExpr(0), priority))
     return;
+  S.Diag(D->getLocation(), diag::warn_global_constructor)
----------------
AaronBallman wrote:

How I see it is:

>From GCC's docs: "The constructor attribute causes the function to be called automatically before execution enters main ()."

And `-Wglobal-constructors` is meant to tell you "this has a constructor which will fire before main" which matters for global and thread local variables, so the `constructor` attribute is sort of morally equivalent.

https://github.com/llvm/llvm-project/pull/129917


More information about the cfe-commits mailing list