[clang] [Clang] Honour [[maybe_unused]] on private fields (PR #187940)

via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 22 11:22:05 PDT 2026


================
@@ -1611,7 +1611,7 @@ void Sema::ActOnEndOfTranslationUnit() {
     RecordCompleteMap MNCComplete;
     for (const NamedDecl *D : UnusedPrivateFields) {
       const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D->getDeclContext());
-      if (RD && !RD->isUnion() &&
+      if (RD && !RD->isUnion() && !RD->hasAttr<UnusedAttr>() &&
----------------
Sirraide wrote:

Wait actually I think you have to check if `D` has the attribute, not `RD` since the latter is the entire class.

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


More information about the cfe-commits mailing list