From f4db55d4e8b7230876c57f1b5f452e3afc9ec26c Mon Sep 17 00:00:00 2001 From: 4c3y <69460051+4c3y@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:30:26 +0100 Subject: [PATCH 1/2] Make MODE_NOLOG compatible with C++11 --- include/log++.h | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/include/log++.h b/include/log++.h index f1f6e88..4bcb014 100644 --- a/include/log++.h +++ b/include/log++.h @@ -446,25 +446,25 @@ LPP_INTL::InternalPolicyLog(LPP_GET_KEY(), n, LPP_INTL::BaseSeverity::DEBUG, LPP #ifdef MODE_NOLOG //lpp #define LOG_2(severity, x) (void) LPP_INTL::LppSeverity::severity; InternalLog() << x -#define LOG_EVERY(severity, n, x) (void) LPP_INTL::LppSeverity::severity; static_assert(std::is_integral_v); InternalLog() -#define LOG_FIRST(severity, n, x) (void) LPP_INTL::LppSeverity::severity; static_assert(std::is_integral_v); InternalLog() -#define LOG_TIMED(severity, t, x) (void) LPP_INTL::LppSeverity::severity; static_assert(std::is_integral_v); InternalLog() +#define LOG_EVERY(severity, n, x) (void) LPP_INTL::LppSeverity::severity; static_assert(std::is_integral::value, ""); InternalLog() +#define LOG_FIRST(severity, n, x) (void) LPP_INTL::LppSeverity::severity; static_assert(std::is_integral::value, ""); InternalLog() +#define LOG_TIMED(severity, t, x) (void) LPP_INTL::LppSeverity::severity; static_assert(std::is_integral::value, ""); InternalLog() //glog #define LOG_1(severity) (void) LPP_INTL::GlogSeverity::severity; InternalLog() #define DLOG(severity) (void) LPP_INTL::GlogSeverity::severity; InternalLog() #define DLOG_EVERY_N(severity, n) (void) LPP_INTL::GlogSeverity::severity; InternalLog() #define LOG_EVERY_N(severity, n) (void) LPP_INTL::GlogSeverity::severity; InternalLog() -#define DLOG_FIRST_N(severity, n) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_integral_v); InternalLog() -#define LOG_FIRST_N(severity, n) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_integral_v); InternalLog() -#define DLOG_IF_EVERY_N(severity, cond, n) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_same::value && std::is_integral_v); InternalLog() +#define DLOG_FIRST_N(severity, n) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_integral::value, ""); InternalLog() +#define LOG_FIRST_N(severity, n) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_integral::value, ""); InternalLog() +#define DLOG_IF_EVERY_N(severity, cond, n) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_same::value && std::is_integral::value, ""); InternalLog() #define LOG_IF_EVERY_N(severity, cond, n) DLOG_IF_EVERY_N(severity, cond, n) -#define LOG_STRING(severity, ptr) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_same*>::value || std::is_same::value); InternalLog() -#define VLOG(verboselevel) static_assert(std::is_integral_v); InternalLog() -#define VLOG_IF(verboselevel, condition) static_assert(std::is_integral_v && std::is_same::value); InternalLog() -#define VLOG_EVERY_N(verboselevel, n) static_assert(std::is_integral_v && std::is_integral_v); InternalLog() -#define VLOG_IF_EVERY_N(verboselevel, condition, n) static_assert(std::is_integral_v && std::is_same::value && std::is_integral_v); InternalLog() -#define DLOG_EVERY_T(severity, t) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_integral_v); InternalLog() +#define LOG_STRING(severity, ptr) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_same*>::value || std::is_same::value, ""); InternalLog() +#define VLOG(verboselevel) static_assert(std::is_integral::value, ""); InternalLog() +#define VLOG_IF(verboselevel, condition) static_assert(std::is_integral::value && std::is_same::value, ""); InternalLog() +#define VLOG_EVERY_N(verboselevel, n) static_assert(std::is_integral::value && std::is_integral::value, ""); InternalLog() +#define VLOG_IF_EVERY_N(verboselevel, condition, n) static_assert(std::is_integral::value && std::is_same::value && std::is_integral::value, ""); InternalLog() +#define DLOG_EVERY_T(severity, t) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_integral::value, ""); InternalLog() #define LOG_EVERY_T(severity, t) DLOG_EVERY_T(severity, t) //ros @@ -480,14 +480,14 @@ LPP_INTL::InternalPolicyLog(LPP_GET_KEY(), n, LPP_INTL::BaseSeverity::DEBUG, LPP #define ROS_ERROR_STREAM(x) LPP_INTL::emptyString(x) #define ROS_FATAL_STREAM(x) LPP_INTL::emptyString(x) -#define ROS_DEBUG_ONCE(...) LOG_2(D, LPP_INTL::emptyString(__VA_ARGS__)) -#define ROS_INFO_ONCE(...) LOG_2(I, LPP_INTL::emptyString(__VA_ARGS__)) -#define ROS_WARN_ONCE(...) LOG_2(W, LPP_INTL::emptyString(__VA_ARGS__)) -#define ROS_ERROR_ONCE(...) LOG_2(E, LPP_INTL::emptyString(__VA_ARGS__)) -#define ROS_FATAL_ONCE(...) LOG_2(F, LPP_INTL::emptyString(__VA_ARGS__)) +#define ROS_DEBUG_ONCE(...) LOG_2(D, std::string(LPP_INTL::emptyString(__VA_ARGS__))) +#define ROS_INFO_ONCE(...) LOG_2(I, std::string(LPP_INTL::emptyString(__VA_ARGS__))) +#define ROS_WARN_ONCE(...) LOG_2(W, std::string(LPP_INTL::emptyString(__VA_ARGS__))) +#define ROS_ERROR_ONCE(...) LOG_2(E, std::string(LPP_INTL::emptyString(__VA_ARGS__))) +#define ROS_FATAL_ONCE(...) LOG_2(F, std::string(LPP_INTL::emptyString(__VA_ARGS__))) -#define ROS_DEBUG_THROTTLE(t, x) static_assert(std::is_integral_v); LPP_INTL::emptyString(x) -#define ROS_DEBUG_STREAM_THROTTLE(t, x) static_assert(std::is_integral_v); InternalLog() +#define ROS_DEBUG_THROTTLE(t, x) static_assert(std::is_integral::value, ""); LPP_INTL::emptyString(x) +#define ROS_DEBUG_STREAM_THROTTLE(t, x) static_assert(std::is_integral::value, ""); InternalLog() #define ROS_INFO_THROTTLE(t, x) ROS_DEBUG_THROTTLE(t, x) #define ROS_INFO_STREAM_THROTTLE(t, x) ROS_DEBUG_STREAM_THROTTLE(t, x) #define ROS_WARN_THROTTLE(t, x) ROS_DEBUG_THROTTLE(t, x) @@ -503,15 +503,15 @@ namespace internal { #ifdef MODE_NOLOG //! Used to disable logging for printf(3) like syntax template -constexpr inline std::string_view emptyString([[maybe_unused]] const char *f, [[maybe_unused]] Args... args) { +constexpr inline const char* emptyString([[maybe_unused]] const char *f, [[maybe_unused]] Args... args) { return ""; } -[[maybe_unused]] constexpr std::string_view emptyString([[maybe_unused]] const char *str) { +[[maybe_unused]] constexpr const char* emptyString([[maybe_unused]] const char *str) { return ""; } -[[maybe_unused]] constexpr std::string_view emptyString([[maybe_unused]] const std::string& str) { +[[maybe_unused]] constexpr const char* emptyString([[maybe_unused]] const std::string& str) { return ""; } #endif From 20782d313454e4f590abaa62063bb314eabd1f36 Mon Sep 17 00:00:00 2001 From: 4c3y <69460051+4c3y@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:30:42 +0100 Subject: [PATCH 2/2] Fixed compile error when using C++11 in async_tests.h --- test/common/async_tests.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/common/async_tests.h b/test/common/async_tests.h index 30ce095..af47ade 100644 --- a/test/common/async_tests.h +++ b/test/common/async_tests.h @@ -5,8 +5,12 @@ #ifndef LOG_TEST_COMMON_ASYNC_TESTS_H_ #define LOG_TEST_COMMON_ASYNC_TESTS_H_ -#include +#if __cplusplus >= 201703L +#include +#endif + #include +#include #define GET_CLASS_NAME(class_ptr, status) abi::__cxa_demangle(typeid(class_ptr).name(), nullptr, nullptr, status) @@ -44,7 +48,12 @@ class TestResult { * @return true on success otherwise false */ inline bool get(const std::string &test_name) { +#if __cplusplus >= 201703L std::scoped_lock lock(test_result_mutex_); +#elif __cplusplus >= 201103L + std::lock_guard lock(test_result_mutex_); +#endif + LOG_INIT(*test_argv); if (!started_) { started_ = true;