[llvm] [llvm][ADT] Mark llvm::IntrusiveRefCntPtr with the warn_unused attribute (PR #211795)
Balázs Benics via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 24 06:50:53 PDT 2026
https://github.com/steakhal created https://github.com/llvm/llvm-project/pull/211795
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.
>From 297041c8e1b0ee34772dc246bab97c2710b7c2d2 Mon Sep 17 00:00:00 2001
From: Balazs Benics <benicsbalazs at gmail.com>
Date: Fri, 24 Jul 2026 14:47:14 +0100
Subject: [PATCH] [llvm][ADT] Mark llvm::IntrusiveRefCntPtr with the
warn_unused attribute
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.
---
llvm/include/llvm/ADT/IntrusiveRefCntPtr.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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:
More information about the llvm-commits
mailing list