blob: b4c2b9c8083392c1f9cfc8569667386dd56cb628 [file] [log] [blame]
Howard Hinnant748a5272010-09-30 21:05:29 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant748a5272010-09-30 21:05:29 +00007//
8//===----------------------------------------------------------------------===//
Jonathan Roelofsb3fcc672014-09-05 19:45:05 +00009//
10// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnant748a5272010-09-30 21:05:29 +000011
12// <atomic>
13
14// struct atomic_flag
15
16// atomic_flag() = default;
17
18#include <atomic>
Howard Hinnantda9ca0b2013-05-02 20:18:43 +000019#include <new>
Howard Hinnant748a5272010-09-30 21:05:29 +000020#include <cassert>
21
Eric Fiselier6ce45e02016-10-12 10:19:48 +000022#include "test_macros.h"
23
Howard Hinnant748a5272010-09-30 21:05:29 +000024int main()
25{
26 std::atomic_flag f;
Eric Fiselierb67e6892015-07-18 21:40:37 +000027 f.clear();
28 assert(f.test_and_set() == 0);
Howard Hinnantda9ca0b2013-05-02 20:18:43 +000029 {
30 typedef std::atomic_flag A;
Eric Fiselier6ce45e02016-10-12 10:19:48 +000031 TEST_ALIGNAS_TYPE(A) char storage[sizeof(A)] = {1};
Howard Hinnantda9ca0b2013-05-02 20:18:43 +000032 A& zero = *new (storage) A();
33 assert(!zero.test_and_set());
34 zero.~A();
35 }
Howard Hinnant748a5272010-09-30 21:05:29 +000036}