From b45c42d6429e7720eca79921c5aacef5f8ef3ac7 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 22 Jan 2024 17:54:39 +0000 Subject: [PATCH] teach clang about reinitialization --- include/grpc/support/port_platform.h | 8 ++++++++ src/core/lib/slice/slice_buffer.h | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h index c1a909db5f50c..d68aadc77de76 100644 --- a/include/grpc/support/port_platform.h +++ b/include/grpc/support/port_platform.h @@ -670,6 +670,14 @@ typedef unsigned __int64 uint64_t; #endif #endif +#ifndef GRPC_REINITIALIZES +#if GPR_HAS_CPP_ATTRIBUTE(clang::reinitializes) +#define GRPC_REINITIALIZES [[clang::reinitializes]] +#else +#define GRPC_REINITIALIZES +#endif +#endif + #ifndef GPR_HAS_ATTRIBUTE #ifdef __has_attribute #define GPR_HAS_ATTRIBUTE(a) __has_attribute(a) diff --git a/src/core/lib/slice/slice_buffer.h b/src/core/lib/slice/slice_buffer.h index 0c1bfe9d9011a..7bf875c88706f 100644 --- a/src/core/lib/slice/slice_buffer.h +++ b/src/core/lib/slice/slice_buffer.h @@ -113,7 +113,9 @@ class SliceBuffer { } /// Removes and unrefs all slices in the SliceBuffer. - void Clear() { grpc_slice_buffer_reset_and_unref(&slice_buffer_); } + GRPC_REINITIALIZES void Clear() { + grpc_slice_buffer_reset_and_unref(&slice_buffer_); + } /// Removes the first slice in the SliceBuffer and returns it. Slice TakeFirst();