From d57a4dddc20b6ebabe0922a775545fee7b06dce0 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 5 Feb 2019 18:16:36 +1100 Subject: [PATCH] debug: pretend to return the same type in `unhandled` --- debug.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/debug.hpp b/debug.hpp index 03ef4372..bc9dbeb0 100644 --- a/debug.hpp +++ b/debug.hpp @@ -524,9 +524,13 @@ unreachable [[noreturn]] (void) /// statements. will almost invariably abort the application. namespace cruft::debug::detail { template - 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>; if constexpr (std::is_enum_v) { unhandled (static_cast> (t)); @@ -540,7 +544,7 @@ namespace cruft::debug::detail { template -constexpr void +constexpr T unhandled [[noreturn]] (T &&t) noexcept { cruft::debug::detail::unhandled (std::forward (t));