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/6] 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/6] 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; From 3b28d157644bd3f48ebd2f651c9af0bb1aafd575 Mon Sep 17 00:00:00 2001 From: 4c3y <69460051+4c3y@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:36:42 +0100 Subject: [PATCH 3/6] Added CI jobs for C++11 and C++14 --- .github/workflows/cpp_ubuntu20_04.yml | 3 ++- CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cpp_ubuntu20_04.yml b/.github/workflows/cpp_ubuntu20_04.yml index 8b9f0ba..8ae7933 100644 --- a/.github/workflows/cpp_ubuntu20_04.yml +++ b/.github/workflows/cpp_ubuntu20_04.yml @@ -12,6 +12,7 @@ jobs: matrix: rosdistro: ['noetic'] gcc: ['8', '9', '10'] + cxx: ['11', '14', '17'] container: ros:${{ matrix.rosdistro }}-ros-base-focal name: ROS ${{ matrix.rosdistro }} - GCC ${{ matrix.gcc }} steps: @@ -35,7 +36,7 @@ jobs: run: sudo apt install -y libgoogle-glog-dev - name: Build lpp - run: source /opt/ros/${{ matrix.rosdistro }}/setup.bash && catkin build lpp && source ${GITHUB_WORKSPACE}/catkin_ws/devel/setup.bash + run: source /opt/ros/${{ matrix.rosdistro }}/setup.bash && catkin build -DCMAKE_CXX_STANDARD=${{ matrix.cxx }} lpp && source ${GITHUB_WORKSPACE}/catkin_ws/devel/setup.bash working-directory: catkin_ws shell: bash diff --git a/CMakeLists.txt b/CMakeLists.txt index b09bffa..262d95a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) endif () # Set standard of top level project or C++17 -if (NOT DEFINED ${CMAKE_CXX_STANDARD}) +if (NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) else () set(CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD}) From 5e03ee47d35b499435e97d688c0d5bc1b054ac4a Mon Sep 17 00:00:00 2001 From: 4c3y <69460051+4c3y@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:41:18 +0100 Subject: [PATCH 4/6] Add C++ standard to job name --- .github/workflows/cpp_ubuntu20_04.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpp_ubuntu20_04.yml b/.github/workflows/cpp_ubuntu20_04.yml index 8ae7933..a899ad2 100644 --- a/.github/workflows/cpp_ubuntu20_04.yml +++ b/.github/workflows/cpp_ubuntu20_04.yml @@ -14,7 +14,7 @@ jobs: gcc: ['8', '9', '10'] cxx: ['11', '14', '17'] container: ros:${{ matrix.rosdistro }}-ros-base-focal - name: ROS ${{ matrix.rosdistro }} - GCC ${{ matrix.gcc }} + name: ROS ${{ matrix.rosdistro }} - GCC ${{ matrix.gcc }} - C++${{ matrix.cxx }} steps: - uses: actions/checkout@v3 name: Checkout lpp From b877594602d87525a5da831e1249c39397b99f4e Mon Sep 17 00:00:00 2001 From: 4c3y <69460051+4c3y@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:43:37 +0100 Subject: [PATCH 5/6] Added CI trigger on push to master --- .github/workflows/cpp_ubuntu20_04.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/cpp_ubuntu20_04.yml b/.github/workflows/cpp_ubuntu20_04.yml index a899ad2..d588868 100644 --- a/.github/workflows/cpp_ubuntu20_04.yml +++ b/.github/workflows/cpp_ubuntu20_04.yml @@ -3,6 +3,9 @@ on: pull_request: branches: - "master" + push: + branches: + - "master" jobs: build: From 48ea7a4ea51e15cf3afb1602bfa9aaf72e2d0e41 Mon Sep 17 00:00:00 2001 From: 4c3y <69460051+4c3y@users.noreply.github.com> Date: Thu, 21 Dec 2023 12:02:48 +0100 Subject: [PATCH 6/6] Added [[maybe_unused]] compiler attribute to argc --- src/demo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/demo.cpp b/src/demo.cpp index 46a0944..24d4306 100644 --- a/src/demo.cpp +++ b/src/demo.cpp @@ -4,7 +4,7 @@ #include -int main(int argc, char **argv) { +int main([[maybe_unused]] int argc, char **argv) { LOG_INIT(argv[0]); int foo = 5;