Home | History | Annotate | Download | only in memory.resource.public
      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 // UNSUPPORTED: c++98, c++03
     11 
     12 // <experimental/memory_resource>
     13 
     14 //------------------------------------------------------------------------------
     15 // TESTING virtual ~memory_resource()
     16 //
     17 // Concerns:
     18 //  A) 'memory_resource' is destructible.
     19 //  B) The destructor is implicitly marked noexcept.
     20 //  C) The destructor is marked virtual.
     21 
     22 #include <experimental/memory_resource>
     23 #include <type_traits>
     24 #include <cassert>
     25 
     26 #include "test_memory_resource.hpp"
     27 
     28 using std::experimental::pmr::memory_resource;
     29 
     30 int main()
     31 {
     32     static_assert(
     33         std::has_virtual_destructor<memory_resource>::value
     34       , "Must have virtual destructor"
     35       );
     36     static_assert(
     37         std::is_nothrow_destructible<memory_resource>::value,
     38         "Must be nothrow destructible"
     39       );
     40     static_assert(
     41         std::is_abstract<memory_resource>::value
     42       , "Must be abstract"
     43       );
     44     // Check that the destructor of `TestResource` is called when
     45     // it is deleted as a pointer to `memory_resource`
     46     {
     47         using TR = TestResource;
     48         memory_resource* M = new TR(42);
     49         assert(TR::resource_alive == 1);
     50         assert(TR::resource_constructed == 1);
     51         assert(TR::resource_destructed == 0);
     52 
     53         delete M;
     54 
     55         assert(TR::resource_alive == 0);
     56         assert(TR::resource_constructed == 1);
     57         assert(TR::resource_destructed == 1);
     58     }
     59 }
     60