1 //===----------------------------------------------------------------------===//
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 //===----------------------------------------------------------------------===//
8 
9 // <functional>
10 
11 // class function<R(ArgTypes...)>
12 
13 // function& operator=(function &&);
14 
15 #include <functional>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 
20 struct A
21 {
22   static std::function<void()> global;
23   static bool cancel;
24 
25   ~A() {
26     DoNotOptimize(cancel);
27     if (cancel)
28       global = std::function<void()>(nullptr);
29   }
30   void operator()() {}
31 };
32 
33 std::function<void()> A::global;
34 bool A::cancel = false;
35 
36 int main(int, char**)
37 {
38   A::global = A();
39   assert(A::global.target<A>());
40 
41   // Check that we don't recurse in A::~A().
42   A::cancel = true;
43   A::global = std::function<void()>(nullptr);
44   assert(!A::global.target<A>());
45 
46   return 0;
47 }
48