From: Jonathan Wakely Date: Tue, 24 Jul 2018 13:03:11 +0000 (+0100) Subject: PR libstdc++/70966 fix lifetime bug for default resource X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0568ade6f8456715ee7ed8902f8e308b0ab3dbb5;p=gcc.git PR libstdc++/70966 fix lifetime bug for default resource PR libstdc++/70966 * include/experimental/memory_resource (__get_default_resource): Use placement new to create an object with dynamic storage duration. From-SVN: r262943 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ba78ab8e914..1f87a12e292 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2018-07-24 Jonathan Wakely + + PR libstdc++/70966 + * include/experimental/memory_resource (__get_default_resource): Use + placement new to create an object with dynamic storage duration. + 2018-07-23 Jonathan Wakely PR libstdc++/70940 diff --git a/libstdc++-v3/include/experimental/memory_resource b/libstdc++-v3/include/experimental/memory_resource index 61273fc2c85..83379d1367a 100644 --- a/libstdc++-v3/include/experimental/memory_resource +++ b/libstdc++-v3/include/experimental/memory_resource @@ -459,12 +459,6 @@ namespace pmr { }; // Global memory resources - inline std::atomic& - __get_default_resource() - { - static atomic _S_default_resource(new_delete_resource()); - return _S_default_resource; - } inline memory_resource* new_delete_resource() noexcept @@ -499,6 +493,16 @@ namespace pmr { } // The default memory resource + + inline std::atomic& + __get_default_resource() + { + using type = atomic; + alignas(type) static unsigned char __buf[sizeof(type)]; + static type* __r = new(__buf) type(new_delete_resource()); + return *__r; + } + inline memory_resource* get_default_resource() noexcept { return __get_default_resource().load(); }