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-Tag: upstream/12.2.0~30211 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0568ade6f8456715ee7ed8902f8e308b0ab3dbb5;p=platform%2Fupstream%2Fgcc.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 ba78ab8..1f87a12 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 61273fc..83379d1 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(); }