aboutsummaryrefslogtreecommitdiff
path: root/libcxx/test/extensions/clang/thread/thread.mutex/lock.verify.cpp
blob: 51ffa6962ac83e09d0b487ab32eae108e05ccd6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: no-threads

// <mutex>

// GCC doesn't have thread safety attributes
// UNSUPPORTED: gcc

// ADDITIONAL_COMPILE_FLAGS: -Wthread-safety -Wno-comment

// XFAIL: FROZEN-CXX03-HEADERS-FIXME

#include <mutex>

#include "test_macros.h"

std::mutex m0;
std::mutex m1;
std::mutex m2;
std::mutex m3;

void f1() {
  std::lock(m0, m1);
} // expected-warning {{mutex 'm0' is still held at the end of function}} \
     expected-warning {{mutex 'm1' is still held at the end of function}}

#if TEST_STD_VER >= 11 && defined(TEST_CLANG_VER) && TEST_CLANG_VER >= 2101
void f2() {
  std::lock(m0, m1, m2);
} // expected-warning {{mutex 'm0' is still held at the end of function}} \
     expected-warning {{mutex 'm1' is still held at the end of function}} \
     expected-warning {{mutex 'm2' is still held at the end of function}}

void f3() {
  std::lock(m0, m1, m2, m3);
} // expected-warning {{mutex 'm0' is still held at the end of function}} \
     expected-warning {{mutex 'm1' is still held at the end of function}} \
     expected-warning {{mutex 'm2' is still held at the end of function}} \
     expected-warning {{mutex 'm3' is still held at the end of function}}
#endif