From abef2b7194d5dd7aac09e3817598dcce86ae2333 Mon Sep 17 00:00:00 2001 From: Grigoris Pavlakis Date: Thu, 26 Aug 2021 02:32:19 +0300 Subject: [PATCH] Fix placement new on zero-sized region warning on GCC 11.1 On latest (11.1 as of this commit) GCC, the following warning is continuously issued during build: warning: placement new constructing an object of type 'SafeNumeric' and size '4' in a region of type 'uint32_t*' {aka 'unsigned int*'} and size '0' [-Wplacement-new=] This happens because on 98ceb60eb4 the new operator override used was dropped and replaced with standard placement new. GCC sees the subtraction from the pointer and complains as it thinks that the SafeNumeric is placed outside an allocation, not knowing that the address requested is already inside one. After suggestions, the false positive is silenced, with no other changes. --- core/templates/cowdata.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/templates/cowdata.h b/core/templates/cowdata.h index ba9babe0af..9b8c0eb528 100644 --- a/core/templates/cowdata.h +++ b/core/templates/cowdata.h @@ -49,6 +49,12 @@ class VMap; SAFE_NUMERIC_TYPE_PUN_GUARANTEES(uint32_t) #endif +// Silence a false positive warning (see GH-52119). +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wplacement-new" +#endif + template class CowData { template @@ -380,4 +386,8 @@ CowData::~CowData() { _unref(_ptr); } +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + #endif // COWDATA_H