[llvm] [llvm][ADT] Mark llvm::IntrusiveRefCntPtr with the warn_unused attribute (PR #211795)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 24 06:51:32 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: Balázs Benics (steakhal)

<details>
<summary>Changes</summary>

IntrusiveRefCntPtr has non-trivial ctor/dtor, thus unused variables wouldn't trigger a warning by default. However, they should. https://clang.llvm.org/docs/AttributeReference.html#warn-unused

Let's mark the class with this attribute get warned about them.

This would have helped catching #<!-- -->211518 and #<!-- -->211517.
Supersedes #<!-- -->211647.

---
Full diff: https://github.com/llvm/llvm-project/pull/211795.diff


1 Files Affected:

- (modified) llvm/include/llvm/ADT/IntrusiveRefCntPtr.h (+1-1) 


``````````diff
diff --git a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
index 90349e02014dd..55f80778823ad 100644
--- a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
+++ b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
@@ -170,7 +170,7 @@ template <typename T> struct IntrusiveRefCntPtrInfo {
 /// This class increments its pointee's reference count when it is created, and
 /// decrements its refcount when it's destroyed (or is changed to point to a
 /// different object).
-template <typename T> class IntrusiveRefCntPtr {
+template <typename T> class [[gnu::warn_unused]] IntrusiveRefCntPtr {
   T *Obj = nullptr;
 
 public:

``````````

</details>


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


More information about the llvm-commits mailing list