Skip to content

Commit 9954b49

Browse files
authored
Include missing version header that could cause segfaults with GCC (#1508)
* Testing GCC json_t issue with version include * flip source order * #include <version> for __cpp_exceptions
1 parent 90e5309 commit 9954b49

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

include/glaze/util/expected.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#pragma once
2626

2727
#include <utility>
28+
#include <version>
2829

2930
#ifndef GLZ_THROW_OR_ABORT
3031
#if __cpp_exceptions

tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ add_subdirectory(reflection)
7575
add_subdirectory(roundtrip)
7676
add_subdirectory(stencil)
7777
add_subdirectory(utility_formats)
78+
add_subdirectory(gcc_json_t_issue)
7879

7980
# We don't run find_package_test or glaze-install_test with MSVC/Windows, because the Github action runner often chokes
8081
# Don't run find_package on Clang, because Linux runs with Clang try to use GCC standard library and have errors before Clang 18

tests/gcc_json_t_issue/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
project(gcc_json_t_issue)
2+
3+
add_executable(${PROJECT_NAME} unused.cpp ${PROJECT_NAME}.cpp)
4+
5+
target_link_libraries(${PROJECT_NAME} PRIVATE glz_test_common)
6+
7+
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})
8+
9+
target_code_coverage(${PROJECT_NAME} AUTO ALL)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <version> // Including this header triggers the undefined behavior, even though it's not otherwise used
2+
#include <glaze/json.hpp>
3+
#include <cassert>
4+
5+
6+
int main(int argc, char const *argv[]) {
7+
(void)argc;
8+
(void)argv;
9+
auto has_value = glz::json_t{}.dump().has_value(); // cause SIGSEGV or SIGABRT
10+
assert(has_value);
11+
return 0;
12+
}

tests/gcc_json_t_issue/unused.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <glaze/json.hpp>
2+
3+
[[maybe_unused]] static bool unused_function() {
4+
return glz::json_t{}.dump().has_value();
5+
}

0 commit comments

Comments
 (0)