Skip to content

Commit 0d95583

Browse files
committed
Add test case from issue #104241
1 parent 97c685c commit 0d95583

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

clang/test/Analysis/block-in-critical-section-inheritance.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,32 @@ void virt_inherited_mutexes_different_bases_tn(CombinedVirtMutex &cvt) {
151151
cvt.unlock2(); // Despite a different name, unlock2 acts on the same mutex as lock1
152152
sleep(10);
153153
}
154+
namespace std {
155+
template <class... MutexTypes> struct scoped_lock {
156+
explicit scoped_lock(MutexTypes&... m);
157+
~scoped_lock();
158+
};
159+
template <class MutexType> class scoped_lock<MutexType> {
160+
public:
161+
explicit scoped_lock(MutexType& m) : m(m) { m.lock(); }
162+
~scoped_lock() { m.unlock(); }
163+
private:
164+
MutexType& m;
165+
};
166+
} // namespace std
167+
168+
namespace gh_104241 {
169+
int magic_number;
170+
std::mutex m;
171+
172+
void fixed() {
173+
int current;
174+
for (int items_processed = 0; items_processed < 100; ++items_processed) {
175+
{
176+
std::scoped_lock<std::mutex> guard(m);
177+
current = magic_number;
178+
}
179+
sleep(current); // expected no warning
180+
}
181+
}
182+
} // namespace gh_104241

0 commit comments

Comments
 (0)