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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 6 08:54:11 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();
+
----------------
erichkeane wrote:

Also, why bother checking if it is ignored?  We should just emit it, and count on the diagnostics engine to suppress it if it is ignored.  We typically only check `isIgnored` if we are going to do 'a lot' of work.

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


More information about the cfe-commits mailing list