diff --git a/include/simsycl/sycl/property.hh b/include/simsycl/sycl/property.hh index 838f94b..86ea108 100644 --- a/include/simsycl/sycl/property.hh +++ b/include/simsycl/sycl/property.hh @@ -12,7 +12,10 @@ namespace simsycl::detail { class property_interface; -} +// outlined into check.cc to avoid cyclic include property.hh -> exception.hh -> context.hh -> property.hh +[[noreturn]] void throw_invalid_property(); + +} // namespace simsycl::detail namespace simsycl::sycl { @@ -46,7 +49,7 @@ class property_list { Property get_property() const { const auto iter = std::find_if(m_properties.begin(), m_properties.end(), [](const std::any &prop) { return prop.type() == typeid(Property); }); - SIMSYCL_CHECK(iter != m_properties.end()); + if(iter == m_properties.end()) { detail::throw_invalid_property(); } return std::any_cast(*iter); } @@ -101,7 +104,7 @@ class property_interface { Property get_property() const { const auto iter = std::find_if(m_properties.begin(), m_properties.end(), [](const std::any &prop) { return prop.type() == typeid(Property); }); - SIMSYCL_CHECK(iter != m_properties.end()); + if(iter == m_properties.end()) { detail::throw_invalid_property(); } return std::any_cast(*iter); } diff --git a/src/simsycl/check.cc b/src/simsycl/check.cc index 6df68b7..9ad316b 100644 --- a/src/simsycl/check.cc +++ b/src/simsycl/check.cc @@ -1,5 +1,6 @@ #include "simsycl/detail/check.hh" #include "simsycl/sycl/exception.hh" +#include "simsycl/sycl/property.hh" // TODO: use std::format/print once widely available #include @@ -51,4 +52,8 @@ void check(bool condition, const char *cond_string, std::source_location locatio } } +void throw_invalid_property() { + throw simsycl::sycl::exception(sycl::errc::invalid, "object does not hold requested property"); +} + } // namespace simsycl::detail \ No newline at end of file