[libcxx-commits] [libcxx] 66ec80c - [libc++][deque] Apply `[[nodiscard]]` to `deque::get_allocator` (#223599)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 15 04:47:14 PDT 2026


Author: Hristo Hristov
Date: 2026-09-15T14:47:08+03:00
New Revision: 66ec80c99d36c2b53d3c5e2b895e2f1eba8bfbe7

URL: https://github.com/llvm/llvm-project/commit/66ec80c99d36c2b53d3c5e2b895e2f1eba8bfbe7
DIFF: https://github.com/llvm/llvm-project/commit/66ec80c99d36c2b53d3c5e2b895e2f1eba8bfbe7.diff

LOG: [libc++][deque] Apply `[[nodiscard]]` to `deque::get_allocator` (#223599)

Added the missing `[[nodiscard]]`.


https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant

Added: 
    

Modified: 
    libcxx/include/deque
    libcxx/test/libcxx/containers/sequences/deque/nodiscard.verify.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/deque b/libcxx/include/deque
index bcd9d9bb4a6dd..ba4d00f81e95e 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -732,7 +732,7 @@ public:
 
   _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __v);
 
-  _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT;
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT;
   _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __alloc_; }
   _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __alloc_; }
 

diff  --git a/libcxx/test/libcxx/containers/sequences/deque/nodiscard.verify.cpp b/libcxx/test/libcxx/containers/sequences/deque/nodiscard.verify.cpp
index c10a99afee8fa..bb64860c84e37 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/nodiscard.verify.cpp
@@ -14,6 +14,8 @@ void test() {
   std::deque<int> d;
   const std::deque<int> cd;
 
+  d.get_allocator(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+
   d.begin();    // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
   cd.begin();   // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
   d.end();      // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}


        


More information about the libcxx-commits mailing list