[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 08:51:54 PST 2025


================
@@ -7596,6 +7596,17 @@ void Sema::ProcessDeclAttributeList(
     D->setInvalidDecl();
   }
 
+  // Warn on global constructors and destructors created by attributes.
+  if (D->hasAttr<ConstructorAttr>() &&
+      !getDiagnostics().isIgnored(diag::warn_global_constructor,
+                                  D->getLocation()))
+    Diag(D->getLocation(), diag::warn_global_constructor)
+        << D->getSourceRange();
+  if (D->hasAttr<DestructorAttr>() &&
+      !getDiagnostics().isIgnored(diag::warn_global_destructor,
+                                  D->getLocation()))
+    Diag(D->getLocation(), diag::warn_global_destructor) << D->getSourceRange();
+
----------------
AaronBallman wrote:

I think this code should live in `handleConstructorAttr()` and `handleDestructorAttr()` instead. (The above code should live there as well, I suspect).

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


More information about the cfe-commits mailing list