Skip to content

Commit

Permalink
Enable C++23, fix gcc-14 and clang-18 builds (#347)
Browse files Browse the repository at this point in the history
* Remove formatter for std::optional

fmt now ships its own.

* Fix experimental::source_location handling

clang 18 moved it out of experimental.

* Enable C++23

Remove unmove, which doesn't compile with C++23 and was only used for
convenience in a test.
  • Loading branch information
frankosterfeld authored Apr 26, 2024
1 parent 77a8245 commit 0fb3758
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 37 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.19)

project(opencmw-cpp CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)

# include(cmake/StandardProjectSettings.cmake)
include(cmake/PreventInSourceBuilds.cmake)
Expand Down Expand Up @@ -126,7 +126,10 @@ if(OPENCMW_ENABLE_TESTING)
if(OPENCMW_ENABLE_COVERAGE)
if(UNIX
AND NOT APPLE
AND NOT CMAKE_CXX_COMPILER_ID MATCHES ".*Clang"
AND NOT
CMAKE_CXX_COMPILER_ID
MATCHES
".*Clang"
AND NOT EMSCRIPTEN) # Linux
message("Coverage reporting enabled")
include(cmake/CodeCoverage.cmake) # https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake #
Expand Down
24 changes: 3 additions & 21 deletions src/core/include/URI.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef OPENCMW_CPP_URI_HPP
#define OPENCMW_CPP_URI_HPP
#include <algorithm>
#include <fmt/format.h>
#include <cassert>
#include <iomanip>
#include <ios>
#include <optional>
Expand All @@ -10,7 +10,8 @@
#include <string_view>
#include <unordered_map>

#include <cassert>
#include <fmt/format.h>
#include <fmt/std.h>

namespace opencmw {

Expand Down Expand Up @@ -476,25 +477,6 @@ struct std::hash<opencmw::URI<check>> {

// fmt::format and std::ostream helper output

// fmt::format and std::ostream helper output for std::optional
template<typename T> // TODO: move to utils class
struct fmt::formatter<std::optional<T>> {
template<typename ParseContext>
constexpr auto parse(ParseContext &ctx) {
return ctx.begin(); // not (yet) implemented
}

template<typename FormatContext>
auto format(std::optional<T> const &v, FormatContext &ctx) const {
return v ? fmt::format_to(ctx.out(), "'{}'", v.value()) : fmt::format_to(ctx.out(), "{{}}");
}
};

template<typename T>
inline std::ostream &operator<<(std::ostream &os, const std::optional<T> &v) {
return os << fmt::format("{}", v);
}

template<opencmw::uri_check check>
struct fmt::formatter<opencmw::URI<check>> {
template<typename ParseContext>
Expand Down
2 changes: 0 additions & 2 deletions src/core/include/opencmw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ constexpr bool always_false = false;
using units::basic_fixed_string;
using units::is_same_v;

constexpr auto &unmove(auto &&t) { return t; } // opposite of std::move(...)

template<typename R, typename Fn, typename... FnArgs>
concept invocable_r = std::is_invocable_r_v<R, Fn, FnArgs...>;

Expand Down
4 changes: 0 additions & 4 deletions src/core/test/00_opencmw_basic_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ static_assert(no_fwd_wrapper(0) == 1, "r-value non-forwarding -> converted to lv
static_assert(fwd_wrapper_verbose(0) == 2, "r-value forwarding");
static_assert(fwd_wrapper(0) == 2, "r-value forwarding");

/**** unmove(..) tests ***/
static_assert(fwd_wrapper(unmove(lvalue)) == 1, "l-value -> l-value forwarding (copy)");
static_assert(fwd_wrapper(unmove(0)) == 1, "r-value -> lvalue forwarding (copy)");

/**** power 2 and bit-magic tests ***/
static_assert(isPower2(1024U));
static_assert(is_power2_v<1024U>);
Expand Down
3 changes: 0 additions & 3 deletions src/core/test/URI_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,6 @@ TEST_CASE("helper methods", "[URI]") {
dummyStream << fmt::format("test std::optional fmt::print: '{}'\n", optional);
REQUIRE(dummyStream.str().size() != 0);
resetStream();
dummyStream << "std::cout std::optional print: " << optional << std::endl;
REQUIRE(dummyStream.str().size() != 0);
resetStream();
}

TEST_CASE("lifetime", "[URI]") {
Expand Down
6 changes: 4 additions & 2 deletions src/serialiser/test/IoSerialiserYaS_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,10 @@ TEST_CASE("IoSerialiser basic syntax", "[IoSerialiser]") {
REQUIRE(opencmw::is_annotated<decltype(data.value)> == true);
std::cout << fmt::format("buffer size (before): {} bytes\n", buffer.size());

opencmw::FieldHeaderWriter<opencmw::YaS>::template put<true>(buffer, unmove(FieldDescriptionShort{ .fieldName = "fieldNameA" }), 43.0);
opencmw::FieldHeaderWriter<opencmw::YaS>::template put<true>(buffer, unmove(FieldDescriptionShort{ .fieldName = "fieldNameB" }), data.value.value());
auto fieldA = FieldDescriptionShort{ .fieldName = "fieldNameA" };
opencmw::FieldHeaderWriter<opencmw::YaS>::template put<true>(buffer, fieldA, 43.0);
auto fieldB = FieldDescriptionShort{ .fieldName = "fieldNameB" };
opencmw::FieldHeaderWriter<opencmw::YaS>::template put<true>(buffer, fieldB, data.value.value());
std::cout << fmt::format("buffer size (after): {} bytes\n", buffer.size());
}
REQUIRE(opencmw::debug::dealloc == opencmw::debug::alloc); // a memory leak occurred
Expand Down
6 changes: 3 additions & 3 deletions src/zmq/include/zmq/ZmqUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
#include <string>
#include <type_traits>

#ifdef __clang__ // TODO: replace (source_location is part of C++20 but still "experimental" for clang
#ifdef __cpp_lib_source_location
#include <source_location>
#else
#include <experimental/source_location>
namespace std {
typedef std::experimental::source_location source_location;
}
#else
#include <source_location>
#endif

#ifndef ENABLE_RESULT_CHECKS
Expand Down

0 comments on commit 0fb3758

Please sign in to comment.