diff --git a/include/openPMD/auxiliary/DerefDynamicCast.hpp b/include/openPMD/auxiliary/DerefDynamicCast.hpp index 6b2674ae9e..ecbf2033e1 100644 --- a/include/openPMD/auxiliary/DerefDynamicCast.hpp +++ b/include/openPMD/auxiliary/DerefDynamicCast.hpp @@ -22,6 +22,7 @@ #include #include +#include namespace openPMD { @@ -64,10 +65,17 @@ namespace auxiliary inline std::optional dynamic_cast_optional(Old_Type *ptr) noexcept { - auto const tmp_ptr = dynamic_cast(ptr); - if (tmp_ptr == nullptr) + try + { + auto const tmp_ptr = dynamic_cast(ptr); + if (tmp_ptr == nullptr) + return std::nullopt; + return {tmp_ptr}; + } + catch (std::bad_cast const &) + { return std::nullopt; - return {tmp_ptr}; + } } } // namespace auxiliary diff --git a/src/Mesh.cpp b/src/Mesh.cpp index d3317070ae..e86283e8c8 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -264,7 +264,7 @@ namespace { for (auto [unit, exponent] : udim) { - *(it + static_cast(unit)) = exponent; + it[static_cast(unit)] = exponent; } } } // namespace