| 1 | // { dg-do compile { target c++11 } } |
| 2 | |
| 3 | #include <mutex> |
| 4 | #include <chrono> |
| 5 | |
| 6 | using namespace std; |
| 7 | |
| 8 | struct Mutex |
| 9 | { |
| 10 | void lock(); |
| 11 | void unlock(); |
| 12 | bool try_lock(); |
| 13 | |
| 14 | bool try_lock_for(chrono::seconds); |
| 15 | bool try_lock_until(chrono::system_clock::time_point); |
| 16 | }; |
| 17 | |
| 18 | |
| 19 | void |
| 20 | test_nodiscard(Mutex& m) |
| 21 | { |
| 22 | unique_lock<Mutex>(); // no warning |
| 23 | unique_lock<Mutex>{}; // no warning |
| 24 | unique_lock<Mutex>(m, defer_lock); // no warning |
| 25 | unique_lock<Mutex>{m, defer_lock}; // no warning |
| 26 | |
| 27 | unique_lock<Mutex>{m}; // { dg-warning "ignoring return value" } |
| 28 | unique_lock<Mutex>{m, try_to_lock}; // { dg-warning "ignoring return value" } |
| 29 | unique_lock<Mutex>(m, try_to_lock); // { dg-warning "ignoring return value" } |
| 30 | unique_lock<Mutex>{m, adopt_lock}; // { dg-warning "ignoring return value" } |
| 31 | unique_lock<Mutex>(m, adopt_lock); // { dg-warning "ignoring return value" } |
| 32 | |
| 33 | chrono::seconds reltime(1); |
| 34 | unique_lock<Mutex>{m, reltime}; // { dg-warning "ignoring return value" } |
| 35 | unique_lock<Mutex>(m, reltime); // { dg-warning "ignoring return value" } |
| 36 | chrono::system_clock::time_point abstime(reltime); |
| 37 | unique_lock<Mutex>{m, abstime}; // { dg-warning "ignoring return value" } |
| 38 | unique_lock<Mutex>(m, abstime); // { dg-warning "ignoring return value" } |
| 39 | } |
| 40 |