debug: pretend to return the same type in unhandled

This commit is contained in:
Danny Robson 2019-02-05 18:16:36 +11:00
parent e7dda93a36
commit d57a4dddc2

View File

@ -524,9 +524,13 @@ unreachable [[noreturn]] (void)
/// statements. will almost invariably abort the application.
namespace cruft::debug::detail {
template <typename T>
void
T
unhandled [[noreturn]] (T &&t) noexcept
{
// If we've been given an enum we should handle it like its underlying
// type so that when we end up logging it we don't accidentally
// trigger an infinite loop of calls to `unhandled` within the
// ostream operator. It doesn't have to be pretty, just functional.
using base_type = std::remove_reference_t<std::decay_t<T>>;
if constexpr (std::is_enum_v<base_type>) {
unhandled (static_cast<std::underlying_type_t<base_type>> (t));
@ -540,7 +544,7 @@ namespace cruft::debug::detail {
template <typename T>
constexpr void
constexpr T
unhandled [[noreturn]] (T &&t) noexcept
{
cruft::debug::detail::unhandled (std::forward<T> (t));