From 9b1ca1d0e7372d78a472d163cf5caeee069e2abe Mon Sep 17 00:00:00 2001 From: RealKC <16511305+RealKC@users.noreply.github.com> Date: Fri, 24 Jan 2020 20:26:42 +0200 Subject: [PATCH] Add `mi_attr_nodiscard_if_cpp20` and mark mi_stl_allocator::allocate overloads as such --- include/mimalloc.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/mimalloc.h b/include/mimalloc.h index 94fcd788..22e54a70 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -20,8 +20,14 @@ terms of the MIT license. A copy of the license can be found in the file #else #define mi_attr_noexcept throw() #endif + #if __cplusplus > 201703L //C++20 + #define mi_attr_nodiscard_if_cpp20 [[nodiscard]] + #else + #define mi_attr_nodiscard_if_cpp20 + #endif #else #define mi_attr_noexcept + #define mi_attr_nodiscard_if_cpp20 #endif #ifdef _MSC_VER @@ -381,8 +387,8 @@ template struct mi_stl_allocator { void deallocate(T* p, size_type) { mi_free(p); } #if (__cplusplus >= 201703L) // C++17 - T* allocate(size_type count) { return static_cast(mi_new_n(count, sizeof(T))); } - T* allocate(size_type count, const void*) { return allocate(count); } + mi_attr_nodiscard_if_cpp20 T* allocate(size_type count) { return static_cast(mi_new_n(count, sizeof(T))); } + mi_attr_nodiscard_if_cpp20 T* allocate(size_type count, const void*) { return allocate(count); } #else pointer allocate(size_type count, const void* = 0) { return static_cast(mi_new_n(count, sizeof(value_type))); } #endif