From 46959535677c4c05cb0a0ed6087182662c1576fb Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Fri, 6 May 2022 16:03:36 -0700 Subject: [PATCH] Avoid exit-time destructors. operator[]() was recently changed to use the existing code in order to correctly align the returned pointer; however this broke -Wexit-time-destructors. Change to a method that is still correctly aligned but does not generate a destructor. --- include/rapidjson/document.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index ea6d806..5136f98 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1230,6 +1230,7 @@ public: else { RAPIDJSON_ASSERT(false); // see above note +#if defined(__cplusplus) && (__cplusplus >= 201103L) // This will generate -Wexit-time-destructors in clang // static GenericValue NullValue; // return NullValue; @@ -1237,6 +1238,10 @@ public: // Use static buffer and placement-new to prevent destruction alignas(GenericValue) static char buffer[sizeof(GenericValue)]; return *new (buffer) GenericValue(); +#else + static GenericValue buffer; + return *new (reinterpret_cast(&buffer)) GenericValue(); +#endif } } template