Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Mar 9, 2022
1 parent 1a65cf6 commit 31684cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
6 changes: 4 additions & 2 deletions include/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
#define ASSERT_DETAIL_PFUNC __extension__ __PRETTY_FUNCTION__
#define ASSERT_DETAIL_ATTR_COLD [[gnu::cold]]
#define ASSERT_DETAIL_ATTR_NOINLINE [[gnu::noinline]]
#define ASSERT_DETAIL_UNREACHABLE __builtin_unreachable()
#else
#define ASSERT_DETAIL_PFUNC __FUNCSIG__
#define ASSERT_DETAIL_ATTR_COLD
#define ASSERT_DETAIL_ATTR_NOINLINE __declspec(noinline)
#define ASSERT_DETAIL_UNREACHABLE __assume(0)
#endif

#if ASSERT_DETAIL_IS_MSVC
Expand All @@ -58,7 +60,7 @@ namespace assert_detail {
check
};

struct assertion_printer;
class assertion_printer;
}

#ifndef ASSERT_FAIL
Expand Down Expand Up @@ -836,7 +838,7 @@ namespace assert_detail {
if(assert_detail_strong_expect(!static_cast<bool>(value), 0)) {
#ifdef NDEBUG
if(params->type == assert_type::assertion) { // will be constant propagated
__builtin_unreachable();
ASSERT_DETAIL_UNREACHABLE;
}
// If an assert fails under -DNDEBUG this whole branch will be marked unreachable but
// without optimizations control flow can fallthrough the above statement. It's of
Expand Down
37 changes: 19 additions & 18 deletions src/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,6 @@
#define RESET ""
#endif

template<typename N> class small_static_map {
const N& needle;
public:
small_static_map(const N& n) : needle(n) {}
template<typename K, typename V, typename... Rest>
constexpr V lookup(const K& option, const V& result, const Rest&... rest) {
if(needle == option) return result;
if constexpr (sizeof...(Rest) > 0) return lookup(rest...);
else assert_detail_primitive_assert(false);
}
constexpr bool is_in() { return false; }
template<typename T, typename... Rest>
constexpr bool is_in(const T& option, const Rest&... rest) {
if(needle == option) return true;
return is_in(rest...);
}
};

namespace assert_detail {
ASSERT_DETAIL_ATTR_COLD
void primitive_assert_impl(bool condition, bool verification, const char* expression,
Expand All @@ -115,6 +97,25 @@ namespace assert_detail {
// Still present in release mode, nonfatal
#define internal_verify(c, ...) primitive_assert_impl(c, true, #c, ASSERT_DETAIL_PFUNC, ##__VA_ARGS__)

// Container utility
template<typename N> class small_static_map {
const N& needle;
public:
small_static_map(const N& n) : needle(n) {}
template<typename K, typename V, typename... Rest>
constexpr V lookup(const K& option, const V& result, const Rest&... rest) {
if(needle == option) return result;
if constexpr (sizeof...(Rest) > 0) return lookup(rest...);
else { assert_detail_primitive_assert(false); ASSERT_DETAIL_UNREACHABLE; }
}
constexpr bool is_in() { return false; }
template<typename T, typename... Rest>
constexpr bool is_in(const T& option, const Rest&... rest) {
if(needle == option) return true;
return is_in(rest...);
}
};

/*
* string utilities
*/
Expand Down

0 comments on commit 31684cf

Please sign in to comment.