From a1c718d5d736ae9fbb29b675f775b70cd14453bd Mon Sep 17 00:00:00 2001
From: Florian Schmaus <flow@cs.fau.de>
Date: Wed, 2 Mar 2022 22:35:09 +0100
Subject: [PATCH] Introduce EMPER_ASSERT_MSG

---
 emper/CountingPrivateSemaphore.cpp | 5 +++--
 emper/Debug.hpp                    | 5 ++++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/emper/CountingPrivateSemaphore.cpp b/emper/CountingPrivateSemaphore.cpp
index d66634c7..3d559dba 100644
--- a/emper/CountingPrivateSemaphore.cpp
+++ b/emper/CountingPrivateSemaphore.cpp
@@ -1,10 +1,11 @@
 // SPDX-License-Identifier: LGPL-3.0-or-later
-// Copyright © 2020-2021 Florian Schmaus
+// Copyright © 2020-2022 Florian Schmaus
 #include "CountingPrivateSemaphore.hpp"
 
 #include <cassert>	// for assert
 
 #include "Context.hpp"	// for Context
+#include "Debug.hpp"
 
 CountingPrivateSemaphore::CountingPrivateSemaphore() : CountingPrivateSemaphore(0) {}
 
@@ -46,7 +47,7 @@ auto CountingPrivateSemaphore::signalInternal() -> Context* {
 		// returns nullptr. In this case the block() function will
 		// have won the race.
 		Context* context = blockedContext.exchange(nullptr);
-		assert(!context || context > (Context*)4096);
+		EMPER_ASSERT_MSG(!context || context > (Context*)4096, "Unexpected context value: " << context);
 		return context;
 	}
 
diff --git a/emper/Debug.hpp b/emper/Debug.hpp
index b6432a99..8be15afb 100644
--- a/emper/Debug.hpp
+++ b/emper/Debug.hpp
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: LGPL-3.0-or-later
-// Copyright © 2020-2021 Florian Schmaus, Florian Fischer
+// Copyright © 2020-2022 Florian Schmaus, Florian Fischer
 #pragma once
 
 #include <atomic>
@@ -8,6 +8,7 @@
 #include <string>
 #include <string_view>
 
+#include "Emper.hpp"
 #include "emper-config.h"
 #include "log/log.hpp"
 
@@ -26,6 +27,8 @@
 // NOLINTNEXTLINE(bugprone-macro-parentheses)
 #define LOG(level, x, log_func) do { if constexpr (level <= EMPER_LOG_LEVEL) { log_func(EMPER_BUILD_STR(x)); } } while (false)
 
+#define EMPER_ASSERT_MSG(expr, msg) do { if constexpr (emper::DEBUG) { if (!(expr)) { DIE_MSG(msg); } } } while (false)
+
 // NOLINTNEXTLINE(bugprone-macro-parentheses)
 #define DBG(x) LOG(Debug, x, emper::log::log_no_prefix);
 
-- 
GitLab