[go: nahoru, domu]

Skip to content

Commit

Permalink
Avoid exit-time destructors.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pkasting authored and miloyip committed May 19, 2022
1 parent 0390b1a commit 4695953
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/rapidjson/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -1230,13 +1230,18 @@ class GenericValue {
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;

// 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>
Expand Down

0 comments on commit 4695953

Please sign in to comment.