diff --git a/libcxx/include/queue b/libcxx/include/queue index b4b79fb25a35f..a1686bc7c502e 100644 --- a/libcxx/include/queue +++ b/libcxx/include/queue @@ -376,12 +376,12 @@ public: # endif // _LIBCPP_CXX03_LANG [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); } - _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); } - _LIBCPP_HIDE_FROM_ABI reference front() { return c.front(); } - _LIBCPP_HIDE_FROM_ABI const_reference front() const { return c.front(); } - _LIBCPP_HIDE_FROM_ABI reference back() { return c.back(); } - _LIBCPP_HIDE_FROM_ABI const_reference back() const { return c.back(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI reference front() { return c.front(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_reference front() const { return c.front(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI reference back() { return c.back(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_reference back() const { return c.back(); } _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v) { c.push_back(__v); } # ifndef _LIBCPP_CXX03_LANG @@ -664,8 +664,10 @@ public: # endif [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); } - _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); } - _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_reference top() const { return c.front(); } + [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); } + [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_reference top() const { + return c.front(); + } _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v); # ifndef _LIBCPP_CXX03_LANG diff --git a/libcxx/test/libcxx/diagnostics/queue.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/queue.nodiscard.verify.cpp index 77d3367cc2f4a..da1f9ff3f01f6 100644 --- a/libcxx/test/libcxx/diagnostics/queue.nodiscard.verify.cpp +++ b/libcxx/test/libcxx/diagnostics/queue.nodiscard.verify.cpp @@ -12,12 +12,24 @@ #include -void test_queue() { - std::queue queue; - queue.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} -} +void test() { + { + std::queue q; + const std::queue cq{}; + + q.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + q.size(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + q.front(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + cq.front(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + q.back(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + cq.back(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + } + + { + std::priority_queue pq; -void test_priority_queue() { - std::priority_queue priority_queue; - priority_queue.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + pq.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + pq.size(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + pq.top(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + } }