From 0ced72650b4cd03529b6bd1184042edb22a5566c Mon Sep 17 00:00:00 2001
From: Florian Fischer <florian.fl.fischer@fau.de>
Date: Sat, 6 Feb 2021 11:50:38 +0100
Subject: [PATCH] write death message to std:err and support stream formatting
 in DIE_MSG*

The stream formatting for DIE_MSG is already wrongly used in
IoContext, EchoClient and LawsDispatcher.
---
 emper/Common.cpp |  2 +-
 emper/Common.hpp | 14 +++++++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/emper/Common.cpp b/emper/Common.cpp
index a65097be..ec820e3f 100644
--- a/emper/Common.cpp
+++ b/emper/Common.cpp
@@ -10,7 +10,7 @@ void die(const char* message, bool usePerror) {
 	if (usePerror) {
 		std::perror(message);
 	} else {
-		std::cout << message << std::endl;
+		std::cerr << message << std::endl;
 	}
 	exit(EXIT_FAILURE);
 }
diff --git a/emper/Common.hpp b/emper/Common.hpp
index fdda0ccf..72136a72 100644
--- a/emper/Common.hpp
+++ b/emper/Common.hpp
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: LGPL-3.0-or-later
-// Copyright © 2020 Florian Schmaus
+// Copyright © 2020-2021 Florian Schmaus, Florian Fischer
 #pragma once
 
 #include <functional>
@@ -9,8 +9,16 @@ using func_t = std::function<void()>;
 #define STRINGIFY(x) #x
 #define TOSTRING(x) STRINGIFY(x)
 #define DIE die(__FILE__ ":" TOSTRING(__LINE__), false)
-#define DIE_MSG(x) die(__FILE__ ":" TOSTRING(__LINE__) " " #x, false)
-#define DIE_MSG_ERRNO(x) die(__FILE__ ":" TOSTRING(__LINE__) " " #x, true)
+
+// See Debug.hpp why we disable clang-format for the multi statement macro definitions
+// clang-format off
+
+// NOLINTNEXTLINE(bugprone-macro-parentheses)
+#define DIE_MSG(x) do { std::stringstream sst; sst << __FILE__ ":" TOSTRING(__LINE__) " " << x; die(sst.str().c_str(), false); } while (false)
+// NOLINTNEXTLINE(bugprone-macro-parentheses)
+#define DIE_MSG_ERRNO(x) do { std::stringstream sst; sst << __FILE__ ":" TOSTRING(__LINE__) " " << x; die(sst.str().c_str(), true); } while (false)
+
+// clang-format on
 
 // We compile with -fno-exceptions for the moment.
 //#define THROW(x) do { throw std::runtime_error(x); } while (false)
-- 
GitLab