From 69aa969199e8bbc2b8e32e155fc32fef1e79b9ab Mon Sep 17 00:00:00 2001 From: daquexian Date: Sat, 11 Jun 2022 11:56:31 +0800 Subject: [PATCH] suppress gcc11 false positive warning Signed-off-by: daquexian --- oneflow/core/common/cached_caller.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/oneflow/core/common/cached_caller.h b/oneflow/core/common/cached_caller.h index 9d8817d6e51..17ad41ac8fd 100644 --- a/oneflow/core/common/cached_caller.h +++ b/oneflow/core/common/cached_caller.h @@ -24,6 +24,17 @@ limitations under the License. #include "oneflow/core/common/maybe.h" #include "oneflow/core/common/tuple_hash.h" +// gcc 11 falsely reports error: +// ‘void operator delete(void*, std::size_t)’ called on unallocated object ‘cache’ +// However, `DeleteAndClear` is only called after `cache` is allocated in +// if (cache == nullptr) block. +// The reason not to use #pragma GCC diagnostic push/pop is that gcc reports +// the error on the caller of `ThreadLocalCachedCall`. +// TODO: replace ThreadLocalCachedCall with ThreadLocalCached decorator? +#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 11 +#pragma GCC diagnostic ignored "-Wfree-nonheap-object" +#endif + namespace oneflow { template