Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support gcc 8 #99

Merged
merged 6 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@ jobs:
working-directory: build
run: |
CTEST_OUTPUT_ON_FAILURE=1 make test
test-linux-gcc-8:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
compiler: [g++-8]
target: [Debug]
steps:
- uses: actions/checkout@v2
- name: dependencies
run: |
sudo apt install gcc-8 g++-8 libgcc-8-dev
python3 -m pip install git+https://github.com/jeffkaufman/icdiff.git
- name: build
run: |
mkdir -p build
cd build
cmake .. \
-DCMAKE_BUILD_TYPE=${{matrix.target}} \
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
-DLIBASSERT_BUILD_TESTING=On
make -j
- name: test
working-directory: build
run: |
CTEST_OUTPUT_ON_FAILURE=1 make test
test-macos:
runs-on: macos-14
strategy:
Expand Down
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,14 @@ if(LIBASSERT_SANITIZER_BUILD)
add_link_options(-fsanitize=address)
endif()

if(LIBASSERT_BUILD_TESTING) # TODO: Maybe remove
if(
LIBASSERT_BUILD_TESTING AND NOT (
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 9.0
)
)
set(LIBASSERT_USE_MAGIC_ENUM ON)
endif()

# add pre-processor definitions corresponding to CMake options
# fixme: supposedly generator expressions should work for this
if(LIBASSERT_USE_MAGIC_ENUM)
set(MAGIC_ENUM_OPT_INSTALL ON)
if(LIBASSERT_USE_EXTERNAL_MAGIC_ENUM)
Expand Down
13 changes: 6 additions & 7 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,14 @@ namespace libassert::detail {
}
};

// copied from cppref
template<typename T, std::size_t N, std::size_t... I>
constexpr std::array<std::remove_cv_t<T>, N> to_array_impl(T(&&a)[N], std::index_sequence<I...>) {
// note: the use of U here is mainly to workaround a gcc 8 issue https://godbolt.org/z/bdsWhdGj3
template<typename T, typename U, std::size_t N, std::size_t... I>
constexpr std::array<std::remove_cv_t<T>, N> to_array_impl(U(&&a)[N], std::index_sequence<I...>) {
return {{std::move(a[I])...}};
}

template<typename T, std::size_t N>
constexpr std::array<std::remove_cv_t<T>, N> to_array(T(&&a)[N]) {
return to_array_impl(std::move(a), std::make_index_sequence<N>{});
template<typename T, typename U, std::size_t N>
constexpr std::array<std::remove_cv_t<T>, N> to_array(U(&&a)[N]) {
return to_array_impl<T>(std::move(a), std::make_index_sequence<N>{});
}

template<typename A, typename B>
Expand Down
62 changes: 32 additions & 30 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
endif()
include(CTest)

set(
demo_sources
add_executable(
demo
tests/demo/bar.cpp
tests/demo/baz/demo.cpp
tests/demo/demo.cpp
tests/demo/foo.cpp
)
add_executable(demo ${demo_sources})
target_link_libraries(demo PRIVATE libassert-lib)
target_compile_options(
demo
PRIVATE
"-DLIBASSERT_USE_MAGIC_ENUM"
"-DLIBASSERT_LOWERCASE"
)
target_compile_definitions(demo PRIVATE LIBASSERT_LOWERCASE)
if(LIBASSERT_USE_MAGIC_ENUM)
target_compile_definitions(demo PRIVATE LIBASSERT_USE_MAGIC_ENUM)
endif()
target_compile_features(
demo
PUBLIC cxx_std_20
Expand All @@ -34,36 +31,41 @@ if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
PUBLIC LIBASSERT_SAFE_COMPARISONS
)

add_executable(integration tests/integration/integration.cpp tests/integration/a.cpp tests/integration/x/a.cpp)
# Temporary workaround for Visual Studio 2022 bug with __builtin_LINE() and __builtin_FILE()
# https://developercommunity.visualstudio.com/t/__builtin_LINE-function-is-reporting-w/10439054?space=62&q=__builtin_function
# TODO: Workaround in the header for end users?
target_compile_features(integration PUBLIC cxx_std_20)
target_link_libraries(integration PRIVATE libassert-lib)
target_compile_options(
integration
PRIVATE
"-DLIBASSERT_USE_MAGIC_ENUM"
"-DLIBASSERT_LOWERCASE"
"-DLIBASSERT_SAFE_COMPARISONS"
)
add_test(
NAME integration
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests
COMMAND
python3 run-tests.py $<TARGET_FILE:integration> ${CMAKE_BUILD_TYPE} ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_STANDARD}
)
if(LIBASSERT_USE_MAGIC_ENUM)
add_executable(integration tests/integration/integration.cpp tests/integration/a.cpp tests/integration/x/a.cpp)
# Temporary workaround for Visual Studio 2022 bug with __builtin_LINE() and __builtin_FILE()
# https://developercommunity.visualstudio.com/t/__builtin_LINE-function-is-reporting-w/10439054?space=62&q=__builtin_function
# TODO: Workaround in the header for end users?
target_compile_features(integration PUBLIC cxx_std_20)
target_link_libraries(integration PRIVATE libassert-lib)
target_compile_definitions(
integration
PRIVATE
LIBASSERT_USE_MAGIC_ENUM
LIBASSERT_LOWERCASE
LIBASSERT_SAFE_COMPARISONS
)
add_test(
NAME integration
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests
COMMAND
python3 run-tests.py $<TARGET_FILE:integration> ${CMAKE_BUILD_TYPE} ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_STANDARD}
)
set(integration_target integration)
else()
set(integration_target)
endif()

set(
dsym_targets
demo
integration
${integration_target}
)

set(
all_targets
demo
integration
${integration_target}
)

include(FetchContent)
Expand Down
46 changes: 38 additions & 8 deletions tests/unit/assertion_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,11 @@ TEST(LibassertBasic, LvalueForwarding) {
EXPECT_EQ(x, 0);
}

#ifdef LIBASSERT_USE_MAGIC_ENUM
enum foo_e { A, B };
enum class bar_e { A, B };
TEST(LibassertBasic, EnumHandling) {
enum foo { A, B };
enum class bar { A, B };
foo a = A;
foo_e a = A;
CHECK(
DEBUG_ASSERT(a != A),
R"XX(
Expand All @@ -721,18 +722,47 @@ TEST(LibassertBasic, EnumHandling) {
| a => A
)XX"
);
bar b = bar::A;
bar_e b = bar_e::A;
CHECK(
DEBUG_ASSERT(b != bar::A),
DEBUG_ASSERT(b != bar_e::A),
R"XX(
|Debug Assertion failed at <LOCATION>:
| DEBUG_ASSERT(b != bar::A);
| DEBUG_ASSERT(b != bar_e::A);
| Where:
| b => A
| bar::A => A
| b => A
| bar_e::A => A
)XX"
);
}
#else
// TODO: Also test this outside of gcc 8
enum foo_e { A, B };
enum class bar_e { A, B };
TEST(LibassertBasic, EnumHandling) {
foo_e a = A;
CHECK(
DEBUG_ASSERT(a != A),
R"XX(
|Debug Assertion failed at <LOCATION>:
| DEBUG_ASSERT(a != A);
| Where:
| a => enum foo_e: 0
| A => enum foo_e: 0
)XX"
);
bar_e b = bar_e::A;
CHECK(
DEBUG_ASSERT(b != bar_e::A),
R"XX(
|Debug Assertion failed at <LOCATION>:
| DEBUG_ASSERT(b != bar_e::A);
| Where:
| b => enum bar_e: 0
| bar_e::A => enum bar_e: 0
)XX"
);
}
#endif

TEST(LibassertBasic, Containers) {
std::set<int> a = { 2, 2, 4, 6, 10 };
Expand Down
Loading