[clang] [clang] Extend -Wunused-but-set-variable to static globals (PR #178342)

Yanzuo Liu via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 21 00:26:40 PST 2026


================
@@ -1212,6 +1212,16 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
       && !isFileVarDecl();
   }
 
+  /// Returns true if a variable is a static file-scope variable.
+  bool isStaticFileVar() const {
+    return isFileVarDecl() && getStorageClass() == SC_Static;
+  }
+
+  /// Returns true if this is a file-scope variable with internal linkage.
+  bool hasInternalLinkageFileVar() const {
+    return isFileVarDecl() && !isExternallyVisible() && !isStaticDataMember();
----------------
zwuis wrote:

Does `isExternallyVisible()` handle static data members expectedly? If yes, could you please try to resolve the TODO comment in this PR now?

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


More information about the cfe-commits mailing list