From ab8519e050602d72fe04110e12a95bfd4937a551 Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Tue, 1 Oct 2024 15:52:48 -0600 Subject: [PATCH] :art: Return a value from `ct_check::emit` Problem: - It's useful to assign the result of `ct_check::emit` to a declared variable in cases where we aren't inside a function. For example, a fallback instantiation of a class template that wants to emit an error can declare a member variable. Solution: - Return a value from `ct_check::emit`. --- include/stdx/ct_string.hpp | 8 ++++++-- test/fail/ct_check.cpp | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/stdx/ct_string.hpp b/include/stdx/ct_string.hpp index 59b599c..b457733 100644 --- a/include/stdx/ct_string.hpp +++ b/include/stdx/ct_string.hpp @@ -124,14 +124,18 @@ template CONSTEVAL auto operator""_cts() { return S; } } // namespace ct_string_literals } // namespace literals +struct ct_check_value {}; + template struct ct_check_t { template constexpr static bool diagnostic = false; template - constexpr static auto emit() -> void + constexpr static auto emit() -> ct_check_value requires diagnostic; }; template <> struct ct_check_t { - template constexpr static auto emit() -> void {} + template constexpr static auto emit() -> ct_check_value { + return {}; + } }; template constexpr auto ct_check = ct_check_t{}; diff --git a/test/fail/ct_check.cpp b/test/fail/ct_check.cpp index 5e70847..21f8909 100644 --- a/test/fail/ct_check.cpp +++ b/test/fail/ct_check.cpp @@ -6,6 +6,6 @@ constexpr auto msg = stdx::ct_string{"01234567890123456789012345678901234567890123456789"}; auto main() -> int { - stdx::ct_check.emit<"not emitted">(); + [[maybe_unused]] auto x = stdx::ct_check.emit<"not emitted">(); stdx::ct_check.emit(); }