[libcxx-commits] [libcxx] [libc++][deque] Apply `[nodiscard]]` to `deque::get_allocator` (PR #223599)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Sep 14 21:30:26 PDT 2026
https://github.com/H-G-Hristov created https://github.com/llvm/llvm-project/pull/223599
https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant
>From ef09c729a0de24ff5989f8463c81043da41dfb49 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 15 Sep 2026 07:29:18 +0300
Subject: [PATCH] [libc++][deque] Apply `[nodiscard]]` to
`deque::get_allocator`
https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant
---
libcxx/include/deque | 2 +-
.../test/libcxx/containers/sequences/deque/nodiscard.verify.cpp | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
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