Skip to content

Commit

Permalink
fix(buffer): make span_buffer compile with GCC < 13 during constant e…
Browse files Browse the repository at this point in the history
…valuation (#89)

Fixes #88
  • Loading branch information
Viatorus authored Mar 9, 2024
1 parent a22b04d commit ef62b3a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmake/dev-mode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ endif ()


if (BUILD_TESTING)
add_subdirectory(test/benchmark)
add_subdirectory(test/compile_test)
add_subdirectory(test/static_analysis)
add_subdirectory(test/unit_test)
add_subdirectory(test/benchmark)
endif ()

if (BUILD_SIZE_COVERAGE)
Expand Down
5 changes: 4 additions & 1 deletion include/emio/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class span_buffer : public buffer {
constexpr span_buffer(span_buffer&&) noexcept = delete;
constexpr span_buffer& operator=(const span_buffer&) = delete;
constexpr span_buffer& operator=(span_buffer&&) noexcept = delete;
constexpr ~span_buffer() override = default;
constexpr ~span_buffer() override;

/**
* Obtains a view over the underlying string object.
Expand Down Expand Up @@ -254,6 +254,9 @@ class span_buffer : public buffer {
std::span<char> span_;
};

// Out-of-line definition because of a GCC bug (93413). Fixed in GCC 13.
inline constexpr span_buffer::~span_buffer() = default;

/**
* This class fulfills the buffer API by providing a fixed-size storage.
* @tparam StorageSize The size of the storage.
Expand Down
21 changes: 21 additions & 0 deletions test/compile_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.14)

project(emioTests LANGUAGES CXX)

include(${CMAKE_SOURCE_DIR}/cmake/project-is-top-level.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/folders.cmake)

if (PROJECT_IS_TOP_LEVEL)
find_package(emio REQUIRED)
enable_testing()
endif ()

add_executable(emio_compile ../compile_test/compile.cpp)

target_link_libraries(emio_compile
emio::emio
)

target_compile_features(emio_compile PRIVATE cxx_std_20)

add_folders(CompileTest)
43 changes: 43 additions & 0 deletions test/compile_test/compile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Created by neubertt on 09.03.2024.
//
#include "emio/emio.hpp"

consteval auto created_with_span_buffer() {
std::array<char, 5> storage{};
emio::span_buffer buf{storage};
return storage;
}

consteval auto created_with_static_buffer() {
std::array<char, 5> storage{};
emio::static_buffer<5> buf{};
std::span<char> area = buf.get_write_area_of(5).value();
std::fill(area.begin(), area.end(), 'a');
std::copy(buf.view().begin(), buf.view().end(), storage.begin());
return storage;
}

consteval auto created_with_memory_buffer() {
std::array<char, 5> storage{};
emio::memory_buffer<0> buf{};
std::span<char> area = buf.get_write_area_of(5).value();
std::fill(area.begin(), area.end(), 'a');
std::copy(buf.view().begin(), buf.view().end(), storage.begin());
return storage;
}

consteval auto created_with_iterator_buffer() {
std::array<char, 5> storage{};
emio::iterator_buffer buf{storage.data()};
std::span<char> area = buf.get_write_area_of(5).value();
std::fill(area.begin(), area.end(), 'a');
return storage;
}

int main() {
created_with_span_buffer();
created_with_static_buffer();
created_with_memory_buffer();
created_with_iterator_buffer();
}

0 comments on commit ef62b3a

Please sign in to comment.