zhiqiang-hhhh commented on code in PR #39030: URL: https://github.com/apache/doris/pull/39030#discussion_r1710550702
########## be/src/vec/common/assert_cast.h: ########## @@ -59,6 +61,34 @@ PURE To assert_cast(From&& from) { demangle(typeid(To).name())); __builtin_unreachable(); #else - return static_cast<To>(from); + if constexpr (check == TypeCheckOnRelease::ENABLE) { + try { + if constexpr (std::is_pointer_v<To>) { + if (typeid(*from) == typeid(std::remove_pointer_t<To>)) { + return static_cast<To>(from); + } + if constexpr (std::is_pointer_v<std::remove_reference_t<From>>) { + if (auto ptr = dynamic_cast<To>(from); ptr != nullptr) { + return ptr; + } + LOG(FATAL) << fmt::format("Bad cast from type:{}* to {}", + demangle(typeid(*from).name()), + demangle(typeid(To).name())); + } + } else { + if (typeid(from) == typeid(To)) { + return static_cast<To>(from); + } + } + } catch (const std::exception& e) { + LOG(FATAL) << "assert cast err:" << e.what(); + } + + LOG(FATAL) << fmt::format("Bad cast from type:{} to {}", demangle(typeid(from).name()), + demangle(typeid(To).name())); + __builtin_unreachable(); Review Comment: `assert_cast` is defined in header file, a new common function defined in this header file will also be visible to the user. So may be we create an anonymous function inside of assert_cast? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org