Skip to content

Commit ab8519e

Browse files
committed
🎨 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`.
1 parent 7976eaf commit ab8519e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

include/stdx/ct_string.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,18 @@ template <ct_string S> CONSTEVAL auto operator""_cts() { return S; }
124124
} // namespace ct_string_literals
125125
} // namespace literals
126126

127+
struct ct_check_value {};
128+
127129
template <bool B> struct ct_check_t {
128130
template <ct_string S> constexpr static bool diagnostic = false;
129131
template <ct_string S>
130-
constexpr static auto emit() -> void
132+
constexpr static auto emit() -> ct_check_value
131133
requires diagnostic<S>;
132134
};
133135
template <> struct ct_check_t<true> {
134-
template <ct_string S> constexpr static auto emit() -> void {}
136+
template <ct_string S> constexpr static auto emit() -> ct_check_value {
137+
return {};
138+
}
135139
};
136140
template <bool B> constexpr auto ct_check = ct_check_t<B>{};
137141

test/fail/ct_check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ constexpr auto msg =
66
stdx::ct_string{"01234567890123456789012345678901234567890123456789"};
77

88
auto main() -> int {
9-
stdx::ct_check<true>.emit<"not emitted">();
9+
[[maybe_unused]] auto x = stdx::ct_check<true>.emit<"not emitted">();
1010
stdx::ct_check<false>.emit<msg>();
1111
}

0 commit comments

Comments
 (0)