Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions libcxx/include/queue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 19 additions & 7 deletions libcxx/test/libcxx/diagnostics/queue.nodiscard.verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@

#include <queue>

void test_queue() {
std::queue<int> queue;
queue.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
}
void test() {
{
std::queue<int> q;
const std::queue<int> 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<int> pq;

void test_priority_queue() {
std::priority_queue<int> 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}}
}
}
Loading