1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <functional>
11 
12 // class function<R(ArgTypes...)>
13 
14 // function& operator=(function &&);
15 
16 #include <functional>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 
21 struct A
22 {
23   static std::function<void()> global;
24   static bool cancel;
25 
~AA26   ~A() {
27     DoNotOptimize(cancel);
28     if (cancel)
29       global = std::function<void()>(nullptr);
30   }
operator ()A31   void operator()() {}
32 };
33 
34 std::function<void()> A::global;
35 bool A::cancel = false;
36 
main()37 int main()
38 {
39   A::global = A();
40   assert(A::global.target<A>());
41 
42   // Check that we don't recurse in A::~A().
43   A::cancel = true;
44   A::global = std::function<void()>(nullptr);
45   assert(!A::global.target<A>());
46 }
47