Skip to content

Commit

Permalink
Fix pretty function and stack traces on msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Mar 20, 2022
1 parent d9b20bd commit b31b852
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 5 additions & 5 deletions include/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,12 +905,12 @@ using asserts::ASSERTION;
// with decltype(auto) in an expression like decltype(auto) x = __extension__ ({...}).y;
#define ASSERT_DETAIL_STMTEXPR(B, R) (__extension__ ({ B R }))
#define ASSERT_DETAIL_WARNING_PRAGMA _Pragma("GCC diagnostic ignored \"-Wparentheses\"")
#define ASSERT_DETAIL_PFUNC_INVOKER_V ASSERT_DETAIL_PFUNC
#define ASSERT_DETAIL_PFUNC_INVOKER_VALUE ASSERT_DETAIL_PFUNC
#define ASSERT_DETAIL_STATIC_CAST_TO_BOOL(x) static_cast<bool>(x)
#else
#define ASSERT_DETAIL_STMTEXPR(B, R) [&] { B return R } ()
#define ASSERT_DETAIL_STMTEXPR(B, R) [&] (const char* assert_detail_msvc_pfunc) { B return R } (ASSERT_DETAIL_PFUNC)
#define ASSERT_DETAIL_WARNING_PRAGMA
#define ASSERT_DETAIL_PFUNC_INVOKER_V nullptr
#define ASSERT_DETAIL_PFUNC_INVOKER_VALUE nullptr
#define ASSERT_DETAIL_STATIC_CAST_TO_BOOL(x) asserts::detail::static_cast_to_bool(x)
namespace asserts::detail {
template<typename T> bool static_cast_to_bool(T&& t) {
Expand Down Expand Up @@ -939,7 +939,7 @@ using asserts::ASSERTION;
name ASSERT_DETAIL_COMMA \
type ASSERT_DETAIL_COMMA \
expr_str ASSERT_DETAIL_COMMA \
ASSERT_DETAIL_PFUNC_INVOKER_V ASSERT_DETAIL_COMMA \
ASSERT_DETAIL_PFUNC_INVOKER_VALUE ASSERT_DETAIL_COMMA \
assert_detail_arg_strings ASSERT_DETAIL_COMMA \
};

Expand All @@ -956,7 +956,7 @@ using asserts::ASSERTION;
// lambdas but that's potentially very expensive compile-time wise. Need to investigate further.
// Note: asserts::detail::expression_decomposer(asserts::detail::expression_decomposer{} << expr) done for ternary
#if ASSERT_DETAIL_IS_MSVC
#define ASSERT_DETAIL_MSVC_PRETTY_FUNCTION_ARG , asserts::detail::msvc_pretty_function_wrapper{ASSERT_DETAIL_PFUNC}
#define ASSERT_DETAIL_MSVC_PRETTY_FUNCTION_ARG ,asserts::detail::msvc_pretty_function_wrapper{assert_detail_msvc_pfunc}
#else
#define ASSERT_DETAIL_MSVC_PRETTY_FUNCTION_ARG
#endif
Expand Down
7 changes: 6 additions & 1 deletion src/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,12 @@ namespace asserts::detail {
end = i;
}
}
return std::pair(start, end);
#if !ASSERT_DETAIL_IS_MSVC
int start_offset = 0;
#else
int start_offset = 1; // accommodate for lambda being used as statement expression
#endif
return std::pair(start + start_offset, end);
}

ASSERT_DETAIL_ATTR_COLD
Expand Down

0 comments on commit b31b852

Please sign in to comment.