From 4426a92d3b46df18bb1707c9adec530dff1ee8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars-Christian=20F=C3=BCrstenberg?= Date: Thu, 22 Aug 2024 10:15:30 +0200 Subject: [PATCH] Fixed C++20/23 build --- .clang-format | 3 +-- CHANGELOG.md | 7 +++++++ CMakeLists.txt | 6 +++--- include/rexsapi/Types.hxx | 14 +++++++++++--- test/TypesTest.cxx | 9 +++++++-- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.clang-format b/.clang-format index 3589067..793a056 100644 --- a/.clang-format +++ b/.clang-format @@ -23,7 +23,7 @@ AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: Yes BinPackArguments: true BinPackParameters: true -BreakBeforeBraces: BS_Custom +BreakBeforeBraces: Custom BraceWrapping: AfterCaseLabel: false AfterClass: false @@ -42,7 +42,6 @@ BraceWrapping: SplitEmptyRecord: true SplitEmptyNamespace: true BreakBeforeBinaryOperators: None -BreakBeforeBraces: Linux BreakBeforeInheritanceComma: false BreakInheritanceList: BeforeComma BreakBeforeTernaryOperators: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 8257c27..f6e4f44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.1.0] + +### Fixed + +- Code now builds with C++20 and C++23 (#53) +- Clang format sytle file fixed (#54) + ## [2.0.0] ### Fixed diff --git a/CMakeLists.txt b/CMakeLists.txt index 9821c04..ecdea63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.22) -project(rexsapi VERSION 2.0.0 LANGUAGES CXX) +project(rexsapi VERSION 2.1.0 LANGUAGES CXX) include(FetchContent) @@ -45,7 +45,7 @@ message(STATUS "Building for ${PLATFORM_NAME}") if(NOT APPLE AND UNIX) if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(REXSAPI_COMPILE_OPTIONS -Wall -Wheader-hygiene -Wcast-align -Wconversion -Wfloat-equal -Wformat=2 -Wmissing-declarations -Woverlength-strings -Wshadow -Wunreachable-code -Wextra -Wpedantic -Wnon-virtual-dtor -Werror -Wno-nested-anon-types -Wdelete-non-virtual-dtor -Wdeprecated -Wfloat-conversion -Wfloat-overflow-conversion -Wmove -Wredundant-move -Wshadow-all -Wsign-compare -Wsign-conversion -Wunreachable-code -Wunused-value -Wignored-qualifiers -Wno-unused-private-field) + set(REXSAPI_COMPILE_OPTIONS -Wall -Wheader-hygiene -Wcast-align -Wconversion -Wfloat-equal -Wformat=2 -Wmissing-declarations -Woverlength-strings -Wshadow -Wextra -Wpedantic -Wnon-virtual-dtor -Werror -Wno-nested-anon-types -Wdelete-non-virtual-dtor -Wdeprecated -Wfloat-conversion -Wfloat-overflow-conversion -Wmove -Wredundant-move -Wshadow-all -Wsign-compare -Wsign-conversion -Wunreachable-code -Wunused-value -Wignored-qualifiers -Wno-unused-private-field) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(REXSAPI_COMPILE_OPTIONS -Wall -Wcast-align -Wconversion -Wfloat-equal -Wformat=2 -Wmissing-declarations -Woverlength-strings -Wshadow -Wunreachable-code -Wextra -Wnon-virtual-dtor -Werror -Wno-psabi -Wignored-qualifiers -Wpedantic) else() @@ -54,7 +54,7 @@ if(NOT APPLE AND UNIX) elseif(WIN32) set(REXSAPI_COMPILE_OPTIONS /W4 /WX) elseif(APPLE) - set(REXSAPI_COMPILE_OPTIONS -g -Wall -Wheader-hygiene -Wcast-align -Wconversion -Wfloat-equal -Wformat=2 -Wmissing-declarations -Woverlength-strings -Wshadow -Wunreachable-code -Wextra -Wpedantic -Wnon-virtual-dtor -Werror -Wno-nested-anon-types -Wdelete-non-virtual-dtor -Wdeprecated -Wfloat-conversion -Wfloat-overflow-conversion -Wmove -Wredundant-move -Wshadow-all -Wsign-compare -Wsign-conversion -Wunreachable-code -Wunused-value -Wignored-qualifiers -Wno-unused-private-field) + set(REXSAPI_COMPILE_OPTIONS -g -Wall -Wheader-hygiene -Wcast-align -Wconversion -Wfloat-equal -Wformat=2 -Wmissing-declarations -Woverlength-strings -Wshadow -Wextra -Wpedantic -Wnon-virtual-dtor -Werror -Wno-nested-anon-types -Wdelete-non-virtual-dtor -Wdeprecated -Wfloat-conversion -Wfloat-overflow-conversion -Wmove -Wredundant-move -Wshadow-all -Wsign-compare -Wsign-conversion -Wunreachable-code -Wunused-value -Wignored-qualifiers -Wno-unused-private-field) else() message(FATAL_ERROR "unsupported platform") endif() diff --git a/include/rexsapi/Types.hxx b/include/rexsapi/Types.hxx index 915866d..d3a1993 100644 --- a/include/rexsapi/Types.hxx +++ b/include/rexsapi/Types.hxx @@ -21,7 +21,16 @@ #include #include +#if __cplusplus >= 202002L || _MSVC_LANG >= 202002L +#include +namespace rexs_date = std::chrono; +namespace rexs_format = std; +#else #include +namespace rexs_date = date; +namespace rexs_format = date; +#endif +#include #include namespace rexsapi @@ -207,9 +216,8 @@ namespace rexsapi */ explicit TDatetime(const std::string& datetime) { - auto op = date::parse("%FT%T%Ez", m_Timepoint); std::istringstream in{datetime}; - in >> op; + in >> rexs_date::parse("%FT%T%Ez", m_Timepoint); if (!in.good()) { throw std::runtime_error{"illegal date specified: " + datetime}; @@ -249,7 +257,7 @@ namespace rexsapi */ inline std::string asUTCString() const { - return date::format("%FT%T%Ez", m_Timepoint); + return rexs_format::format("%FT%T%Ez", m_Timepoint); } /** diff --git a/test/TypesTest.cxx b/test/TypesTest.cxx index 52f3950..d51c895 100644 --- a/test/TypesTest.cxx +++ b/test/TypesTest.cxx @@ -159,8 +159,13 @@ TEST_CASE("Datetime test") SUBCASE("Parse") { const rexsapi::TDatetime dt{"2023-03-28T13:49:36+02:00"}; - using namespace date; - CHECK(dt.asTimepoint() == date::sys_days{2023_y / mar / 28} + std::chrono::hours{11} + std::chrono::minutes{49} + +#if __cplusplus >= 202002L || _MSVC_LANG >= 202002L + auto rexs_march = std::chrono::March; +#else + auto rexs_march = date::mar; +#endif + CHECK(dt.asTimepoint() == rexs_date::sys_days{rexs_date::year{2023} / rexs_march / 28} + std::chrono::hours{11} + + std::chrono::minutes{49} + std::chrono::seconds{36}); CHECK(dt.asUTCString() == "2023-03-28T11:49:36+00:00"); const auto s = dt.asLocaleString();