From f96db8d9950cb48e01ffa3845a635f8c0e1db40d Mon Sep 17 00:00:00 2001 From: yang-jihai Date: Fri, 29 Aug 2025 17:55:20 +0800 Subject: [PATCH 1/2] AnyCast throw BadAnyCast Signed-off-by: yang-jihai --- interface/inner_api/meta/any.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interface/inner_api/meta/any.h b/interface/inner_api/meta/any.h index d4f8cdbf..037739de 100644 --- a/interface/inner_api/meta/any.h +++ b/interface/inner_api/meta/any.h @@ -850,6 +850,9 @@ ValueType AnyCast(const Any& other) "any_cast(const any&) requires ValueType constructable from const " "remove_cv_t>&"); auto ptr = AnyCast(&other); + if (ptr == nullptr) { + throw BadAnyCast(); + } return static_cast(*ptr); } -- Gitee From 7960a24f0de299ed644ce646d24847c518637bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BB=A7=E6=B5=B7?= Date: Fri, 29 Aug 2025 10:24:43 +0000 Subject: [PATCH 2/2] update interface/inner_api/meta/any.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨继海 --- interface/inner_api/meta/any.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/inner_api/meta/any.h b/interface/inner_api/meta/any.h index 037739de..09abf0f5 100644 --- a/interface/inner_api/meta/any.h +++ b/interface/inner_api/meta/any.h @@ -851,7 +851,7 @@ ValueType AnyCast(const Any& other) "remove_cv_t>&"); auto ptr = AnyCast(&other); if (ptr == nullptr) { - throw BadAnyCast(); + return BadAnyCast(); } return static_cast(*ptr); } -- Gitee