From 125426516ad8b93d9f842c59f22ffb2e97e98a60 Mon Sep 17 00:00:00 2001 From: Dmitry Arkhipov Date: Thu, 22 Oct 2026 11:53:56 +0300 Subject: [PATCH 1/2] allow disabling reliance on no_destroy attribute support --- include/boost/json/detail/config.hpp | 8 ++++++-- include/boost/json/detail/default_resource.hpp | 8 ++++---- include/boost/json/detail/impl/default_resource.ipp | 6 +++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/boost/json/detail/config.hpp b/include/boost/json/detail/config.hpp index a11cc0561..5efb2a89b 100644 --- a/include/boost/json/detail/config.hpp +++ b/include/boost/json/detail/config.hpp @@ -40,11 +40,15 @@ # endif #endif -#ifndef BOOST_JSON_NO_DESTROY +#ifndef BOOST_JSON_NO_ATTRIBUTE_NO_DESTROY # if defined(__clang__) && defined(__has_cpp_attribute) # if __has_cpp_attribute(clang::no_destroy) -# define BOOST_JSON_NO_DESTROY [[clang::no_destroy]] +# define BOOST_JSON_ATTRIBUTE_NO_DESTROY [[clang::no_destroy]] +# else +# define BOOST_JSON_NO_ATTRIBUTE_NO_DESTROY # endif +# else +# define BOOST_JSON_NO_ATTRIBUTE_NO_DESTROY # endif #endif diff --git a/include/boost/json/detail/default_resource.hpp b/include/boost/json/detail/default_resource.hpp index 08b986225..a5c53948f 100644 --- a/include/boost/json/detail/default_resource.hpp +++ b/include/boost/json/detail/default_resource.hpp @@ -33,12 +33,12 @@ default_resource final union holder; #ifndef BOOST_JSON_WEAK_CONSTINIT -# ifndef BOOST_JSON_NO_DESTROY +# ifdef BOOST_JSON_NO_ATTRIBUTE_NO_DESTROY static holder instance_; -# else - BOOST_JSON_NO_DESTROY +# else // BOOST_JSON_NO_ATTRIBUTE_NO_DESTROY + BOOST_JSON_ATTRIBUTE_NO_DESTROY static default_resource instance_; -# endif +# endif // BOOST_JSON_NO_ATTRIBUTE_NO_DESTROY #endif public: diff --git a/include/boost/json/detail/impl/default_resource.ipp b/include/boost/json/detail/impl/default_resource.ipp index 4eee8304d..6b927c038 100644 --- a/include/boost/json/detail/impl/default_resource.ipp +++ b/include/boost/json/detail/impl/default_resource.ipp @@ -17,15 +17,15 @@ namespace json { namespace detail { #ifndef BOOST_JSON_WEAK_CONSTINIT -# ifndef BOOST_JSON_NO_DESTROY +# ifdef BOOST_JSON_NO_ATTRIBUTE_NO_DESTROY BOOST_JSON_REQUIRE_CONST_INIT default_resource::holder default_resource::instance_; -# else +# else // BOOST_JSON_NO_ATTRIBUTE_NO_DESTROY BOOST_JSON_REQUIRE_CONST_INIT default_resource default_resource::instance_; -# endif +# endif // BOOST_JSON_NO_ATTRIBUTE_NO_DESTROY #endif // this is here so that ~memory_resource From 5cdaa661dfedd0e77f0af87265d28f3444b222c7 Mon Sep 17 00:00:00 2001 From: Dmitry Arkhipov Date: Fri, 23 Oct 2026 10:03:32 +0300 Subject: [PATCH 2/2] do not use no_destroy in clang-cl MSVC does not support it, and the point of clang-cl is to produce code that is compatible with MSVC. --- include/boost/json/detail/config.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/json/detail/config.hpp b/include/boost/json/detail/config.hpp index 5efb2a89b..933c5de2c 100644 --- a/include/boost/json/detail/config.hpp +++ b/include/boost/json/detail/config.hpp @@ -41,7 +41,8 @@ #endif #ifndef BOOST_JSON_NO_ATTRIBUTE_NO_DESTROY -# if defined(__clang__) && defined(__has_cpp_attribute) + // clang, but not clang-cl +# if defined(__clang__) && !defined(_MSC_VER) && defined(__has_cpp_attribute) # if __has_cpp_attribute(clang::no_destroy) # define BOOST_JSON_ATTRIBUTE_NO_DESTROY [[clang::no_destroy]] # else