diff options
author | Peter Kasting <pkasting@chromium.org> | 2022-05-07 02:03:36 +0300 |
---|---|---|
committer | Milo Yip <miloyip@gmail.com> | 2022-05-19 06:55:17 +0300 |
commit | 46959535677c4c05cb0a0ed6087182662c1576fb (patch) | |
tree | cc559fa109ab6fe18cad287f807944e6b13e1ed6 | |
parent | 0390b1ad5753f94284bba8c7fa8acb97640b9212 (diff) |
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.
-rw-r--r-- | include/rapidjson/document.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index ea6d8069..5136f981 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<char *>(&buffer)) GenericValue(); +#endif } } template <typename SourceAllocator> |