Skip to content

Commit

Permalink
Fixed C++20/23 build
Browse files Browse the repository at this point in the history
  • Loading branch information
fuersten committed Aug 22, 2024
1 parent 5492b76 commit 4426a92
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BreakBeforeBraces: BS_Custom
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
Expand All @@ -42,7 +42,6 @@ BraceWrapping:
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Linux
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
14 changes: 11 additions & 3 deletions include/rexsapi/Types.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@
#include <rexsapi/Exception.hxx>
#include <rexsapi/Format.hxx>

#if __cplusplus >= 202002L || _MSVC_LANG >= 202002L
#include <chrono>
namespace rexs_date = std::chrono;
namespace rexs_format = std;
#else
#include <date/date.h>
namespace rexs_date = date;
namespace rexs_format = date;
#endif
#include <sstream>
#include <vector>

namespace rexsapi
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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);
}

/**
Expand Down
9 changes: 7 additions & 2 deletions test/TypesTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 4426a92

Please sign in to comment.