Skip to content

Commit 4afaf9b

Browse files
committed
🐛 [fatal] Source Location is not present
Problem: - When `fatal` expression is triggered the source location is not shown correclty. Solution: - Use `value_location<fatal>` with `operator>>` to get the source location.
1 parent 5f0f96e commit 4afaf9b

File tree

1 file changed

+14
-34
lines changed

1 file changed

+14
-34
lines changed

include/boost/ut.hpp

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,26 +1790,26 @@ template <class... Ts, class TEvent>
17901790
}
17911791
};
17921792

1793-
template <class T>
1793+
template <class TExpr>
17941794
struct fatal_ : op {
17951795
using type = fatal_;
17961796

1797-
constexpr explicit fatal_(const T& t) : t_{t} {}
1797+
constexpr explicit fatal_(const TExpr& expr) : expr_{expr} {}
17981798

17991799
[[nodiscard]] constexpr operator bool() const {
1800-
if (static_cast<bool>(t_)) {
1800+
if (static_cast<bool>(expr_)) {
18011801
} else {
18021802
cfg::wip = true;
1803-
void(
1804-
on<T>(events::assertion<T>{.expr = t_, .location = cfg::location}));
1805-
on<T>(events::fatal_assertion{});
1803+
void(on<TExpr>(events::assertion<TExpr>{.expr = expr_,
1804+
.location = cfg::location}));
1805+
on<TExpr>(events::fatal_assertion{});
18061806
}
1807-
return static_cast<bool>(t_);
1807+
return static_cast<bool>(expr_);
18081808
}
18091809

1810-
[[nodiscard]] constexpr decltype(auto) get() const { return t_; }
1810+
[[nodiscard]] constexpr decltype(auto) get() const { return expr_; }
18111811

1812-
T t_{};
1812+
TExpr expr_{};
18131813
};
18141814

18151815
template <class T>
@@ -1997,19 +1997,9 @@ template <class... Ts, class TEvent>
19971997
return detail::not_{t};
19981998
}
19991999

2000-
template <class T, type_traits::requires_t<type_traits::is_op_v<T>> = 0>
2001-
[[nodiscard]] inline auto operator>>(const T& t, const detail::fatal&) {
2002-
return detail::fatal_{t};
2003-
}
2004-
2000+
template <class T>
20052001
[[nodiscard]] inline auto operator>>(
2006-
const detail::value_location<detail::that_::expr<bool>>& t,
2007-
const detail::fatal&) {
2008-
return detail::fatal_{t.get()};
2009-
}
2010-
2011-
[[nodiscard]] inline auto operator>>(const detail::value_location<bool>& t,
2012-
const detail::fatal&) {
2002+
const T& t, const detail::value_location<detail::fatal>&) {
20132003
return detail::fatal_{t};
20142004
}
20152005

@@ -2080,8 +2070,9 @@ template <class... Ts, class TEvent>
20802070
return detail::value<T>{t};
20812071
}
20822072

2083-
template <class T, type_traits::requires_t<type_traits::is_op_v<T>> = 0>
2084-
inline auto operator>>(const T& t, const detail::fatal&) {
2073+
template <class T>
2074+
inline auto operator>>(const T& t,
2075+
const detail::value_location<detail::fatal>&) {
20852076
using fatal_t = detail::fatal_<T>;
20862077
struct fatal_ : fatal_t {
20872078
using type [[maybe_unused]] = fatal_t;
@@ -2091,17 +2082,6 @@ template <class... Ts, class TEvent>
20912082
return fatal_{t};
20922083
}
20932084

2094-
inline auto operator>>(const detail::value_location<bool>& t,
2095-
const detail::fatal&) {
2096-
using fatal_t = detail::fatal_<bool>;
2097-
struct fatal_ : fatal_t {
2098-
using type [[maybe_unused]] = fatal_t;
2099-
using fatal_t::fatal_t;
2100-
const detail::terse_<fatal_t> _{*this};
2101-
};
2102-
return fatal_{t.get()};
2103-
}
2104-
21052085
template <class T, type_traits::requires_t<type_traits::is_op_v<T>> = 0>
21062086
constexpr auto operator==(
21072087
const T& lhs, const detail::value_location<typename T::value_type>& rhs) {

0 commit comments

Comments
 (0)