libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

nullptr_t_assign_reentrant.pass.cpp (941B)


      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=(nullptr_t);
     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 
     26   ~A() {
     27     DoNotOptimize(cancel);
     28     if (cancel)
     29       global = nullptr;
     30   }
     31   void operator()() {}
     32 };
     33 
     34 std::function<void()> A::global;
     35 bool A::cancel = false;
     36 
     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 = nullptr;
     45   assert(!A::global.target<A>());
     46 }