1 | // RUN: %clang_cc1 -std=c++11 %s -verify -Wthread-safety-analysis |
2 | |
3 | class Mutex { |
4 | public: |
5 | void Lock() __attribute__((exclusive_lock_function())); |
6 | void Unlock() __attribute__((unlock_function())); |
7 | }; |
8 | |
9 | class A { |
10 | public: |
11 | Mutex mu1, mu2; |
12 | |
13 | void foo() __attribute__((exclusive_locks_required(mu1))) __attribute__((exclusive_locks_required(mu2))) {} |
14 | |
15 | template <class T> void bar() __attribute__((exclusive_locks_required(mu1))) __attribute__((exclusive_locks_required(mu2))) { |
16 | foo(); |
17 | } |
18 | }; |
19 | |
20 | void f() { |
21 | A a; |
22 | a.mu1.Lock(); |
23 | a.mu2.Lock(); |
24 | a.bar<int>(); |
25 | a.mu2.Unlock(); |
26 | a.bar<int>(); // expected-warning {{calling function 'bar<int>' requires holding mutex 'a.mu2' exclusively}} |
27 | a.mu1.Unlock(); |
28 | a.bar<int>(); // expected-warning {{calling function 'bar<int>' requires holding mutex 'a.mu1' exclusively}} \ |
29 | expected-warning {{calling function 'bar<int>' requires holding mutex 'a.mu2' exclusively}} |
30 | } |
31 | |