[clang] Document the warn_unused attribute (PR #201881)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 8 04:12:06 PDT 2026


================
@@ -388,6 +388,34 @@ pointer, but not any provenance of the allocation:
   }];
 }
 
+def WarnUnusedDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+The ``warn_unused`` attribute can be placed on the declaration of a structure or union type.
+When the ``-Wunused-variable`` diagnostic is enabled, local variables of types which have a non-trivial constructor or destructor are considered "used" by virtue of the constructor or destructor invocations involved.
+Declaring the type with the ``warn_unused`` attribute strengthens the "use" requirements to require a direct access to the variable, such as passing it as an argument to a call, calling a member function on it, taking the address of it, etc.
----------------
Fznamznon wrote:

I probably can't read just like always but `declaring the type with the ``warn_unused`` attribute strengthens the "use" requirements` reads like adding the attribute will avoid the warning at a first glance. I wonder if just saying directly the warning will appear due to the attribute where it normally doesn't  will make it slightly less confusing and easier to read?

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


More information about the cfe-commits mailing list