From 89fa6c9d3ff6f99cd4307613d55567afa7201979 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Wed, 8 May 2024 20:40:27 +0800 Subject: [PATCH] fix a bug of `any` --- include/pocketpy/any.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/pocketpy/any.h b/include/pocketpy/any.h index 580c5dce..40daaa9d 100644 --- a/include/pocketpy/any.h +++ b/include/pocketpy/any.h @@ -14,7 +14,7 @@ struct any{ inline static vtable* get(){ static_assert(std::is_same_v>); if constexpr (is_sso_v){ - static vtable vt{ typeid(T), [](void*){} }; + static vtable vt{ typeid(T), nullptr }; return &vt; }else{ static vtable vt{ typeid(T), [](void* ptr){ delete static_cast(ptr); } }; @@ -28,7 +28,7 @@ struct any{ any() : data(nullptr), _vt(nullptr) {} - explicit operator bool() const { return data != nullptr; } + explicit operator bool() const { return _vt != nullptr; } template any(T&& value){ @@ -52,7 +52,7 @@ struct any{ any(const any& other) = delete; any& operator=(const any& other) = delete; - ~any() { if(data) _vt->deleter(data); } + ~any() { if(_vt && _vt->deleter) _vt->deleter(data); } template T& _cast() const noexcept{