Clang] Fix expansion of response files in -Wp after integrated-cc1 change
[llvm-project.git] / libcxxabi / test / thread_local_destruction_order.pass.cpp
blob388cdc439fb0a605f5d2550842c0b0d04a555553
1 //===-------------- thread_local_destruction_order.pass.cpp ---------------===//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
9 // Darwin TLV finalization routines fail when creating a thread-local variable
10 // in the destructor for another thread-local variable:
11 // http://lists.llvm.org/pipermail/cfe-dev/2016-November/051376.html
12 // XFAIL: darwin
13 // UNSUPPORTED: c++98, c++03
14 // UNSUPPORTED: libcxxabi-no-threads
16 #include <cassert>
17 #include <thread>
19 int seq = 0;
21 class OrderChecker {
22 public:
23 explicit OrderChecker(int n) : n_{n} { }
25 ~OrderChecker() {
26 assert(seq++ == n_);
29 private:
30 int n_;
33 template <int ID>
34 class CreatesThreadLocalInDestructor {
35 public:
36 ~CreatesThreadLocalInDestructor() {
37 thread_local OrderChecker checker{ID};
41 OrderChecker global{7};
43 void thread_fn() {
44 static OrderChecker fn_static{5};
45 thread_local CreatesThreadLocalInDestructor<2> creates_tl2;
46 thread_local OrderChecker fn_thread_local{1};
47 thread_local CreatesThreadLocalInDestructor<0> creates_tl0;
50 int main() {
51 static OrderChecker fn_static{6};
53 std::thread{thread_fn}.join();
54 assert(seq == 3);
56 thread_local OrderChecker fn_thread_local{4};
57 thread_local CreatesThreadLocalInDestructor<3> creates_tl;
59 return 0;