blob: 6a0d907fde94f71768883e7dda11718392d1d5a7 [file] [log] [blame]
Howard Hinnant748a5272010-09-30 21:05:29 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnant748a5272010-09-30 21:05:29 +00006//
7//===----------------------------------------------------------------------===//
Jonathan Roelofsb3fcc672014-09-05 19:45:05 +00008//
9// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnant748a5272010-09-30 21:05:29 +000010
11// <atomic>
12
13// struct atomic_flag
14
15// atomic_flag() = default;
16
17#include <atomic>
Howard Hinnantda9ca0b2013-05-02 20:18:43 +000018#include <new>
Howard Hinnant748a5272010-09-30 21:05:29 +000019#include <cassert>
20
Eric Fiselier6ce45e02016-10-12 10:19:48 +000021#include "test_macros.h"
22
JF Bastien2df59c52019-02-04 20:31:13 +000023int main(int, char**)
Howard Hinnant748a5272010-09-30 21:05:29 +000024{
25 std::atomic_flag f;
Eric Fiselierb67e6892015-07-18 21:40:37 +000026 f.clear();
27 assert(f.test_and_set() == 0);
Howard Hinnantda9ca0b2013-05-02 20:18:43 +000028 {
29 typedef std::atomic_flag A;
Eric Fiselier6ce45e02016-10-12 10:19:48 +000030 TEST_ALIGNAS_TYPE(A) char storage[sizeof(A)] = {1};
Howard Hinnantda9ca0b2013-05-02 20:18:43 +000031 A& zero = *new (storage) A();
32 assert(!zero.test_and_set());
33 zero.~A();
34 }
JF Bastien2df59c52019-02-04 20:31:13 +000035
36 return 0;
Howard Hinnant748a5272010-09-30 21:05:29 +000037}