1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // UNSUPPORTED: no-threads
10
11 // [[nodiscard]] isn't supported in C++03 (not even as an extension)
12 // UNSUPPORTED: c++03
13
14 // <mutex>
15
16 // template <class Mutex> class lock_guard;
17
18 // [[nodiscard]] explicit lock_guard(mutex_type& m);
19 // [[nodiscard]] lock_guard(mutex_type& m, adopt_lock_t);
20
21 // Test that we properly apply [[nodiscard]] to lock_guard's constructors,
22 // which is a libc++ extension.
23
24 #include <mutex>
25
f()26 void f() {
27 std::mutex m;
28 std::lock_guard<std::mutex>{m}; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
29 std::lock_guard<std::mutex>{m, std::adopt_lock}; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
30 }
31