brintos

brintos / llvm-project-archived public Read only

0
0
Text · 575 B · ed0280b Raw
20 lines · cpp
1// RUN: %clang_cc1 -verify -fsyntax-only -Wthread-safety %s2 3struct __attribute__((lockable)) Lock {};4 5void sink_protected(int);6 7struct Baz {8public:9    Lock lock_;10    int protected_num_ __attribute__((guarded_by(lock_))) = 1;11};12 13void paren_test() {14    Baz baz;     15    int& n = baz.protected_num_;16    sink_protected(n); // expected-warning{{reading variable 'protected_num_' requires holding mutex 'baz.lock_'}}17    int& n2 = (baz.protected_num_);18    sink_protected(n2); // expected-warning{{reading variable 'protected_num_' requires holding mutex 'baz.lock_'}}19}20