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

Include missing version header that could cause segfaults with GCC #1508

Merged
merged 4 commits into from
Dec 18, 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
1 change: 1 addition & 0 deletions include/glaze/util/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#pragma once

#include <utility>
#include <version>

#ifndef GLZ_THROW_OR_ABORT
#if __cpp_exceptions
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ add_subdirectory(reflection)
add_subdirectory(roundtrip)
add_subdirectory(stencil)
add_subdirectory(utility_formats)
add_subdirectory(gcc_json_t_issue)

# We don't run find_package_test or glaze-install_test with MSVC/Windows, because the Github action runner often chokes
# Don't run find_package on Clang, because Linux runs with Clang try to use GCC standard library and have errors before Clang 18
Expand Down
9 changes: 9 additions & 0 deletions tests/gcc_json_t_issue/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
project(gcc_json_t_issue)

add_executable(${PROJECT_NAME} unused.cpp ${PROJECT_NAME}.cpp)

target_link_libraries(${PROJECT_NAME} PRIVATE glz_test_common)

add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

target_code_coverage(${PROJECT_NAME} AUTO ALL)
12 changes: 12 additions & 0 deletions tests/gcc_json_t_issue/gcc_json_t_issue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <version> // Including this header triggers the undefined behavior, even though it's not otherwise used
#include <glaze/json.hpp>
#include <cassert>


int main(int argc, char const *argv[]) {
(void)argc;
(void)argv;
auto has_value = glz::json_t{}.dump().has_value(); // cause SIGSEGV or SIGABRT
assert(has_value);
return 0;
}
5 changes: 5 additions & 0 deletions tests/gcc_json_t_issue/unused.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <glaze/json.hpp>

[[maybe_unused]] static bool unused_function() {
return glz::json_t{}.dump().has_value();
}