diff --git a/include/glaze/util/expected.hpp b/include/glaze/util/expected.hpp index a21ddcb6b4..b262047b37 100644 --- a/include/glaze/util/expected.hpp +++ b/include/glaze/util/expected.hpp @@ -25,6 +25,7 @@ #pragma once #include +#include #ifndef GLZ_THROW_OR_ABORT #if __cpp_exceptions diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 287ee67d09..3c8f9bc573 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 diff --git a/tests/gcc_json_t_issue/CMakeLists.txt b/tests/gcc_json_t_issue/CMakeLists.txt new file mode 100644 index 0000000000..1b6b267cb5 --- /dev/null +++ b/tests/gcc_json_t_issue/CMakeLists.txt @@ -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) diff --git a/tests/gcc_json_t_issue/gcc_json_t_issue.cpp b/tests/gcc_json_t_issue/gcc_json_t_issue.cpp new file mode 100644 index 0000000000..896cc40aa9 --- /dev/null +++ b/tests/gcc_json_t_issue/gcc_json_t_issue.cpp @@ -0,0 +1,12 @@ +#include // Including this header triggers the undefined behavior, even though it's not otherwise used +#include +#include + + +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; +} diff --git a/tests/gcc_json_t_issue/unused.cpp b/tests/gcc_json_t_issue/unused.cpp new file mode 100644 index 0000000000..b7ec951f54 --- /dev/null +++ b/tests/gcc_json_t_issue/unused.cpp @@ -0,0 +1,5 @@ +#include + +[[maybe_unused]] static bool unused_function() { + return glz::json_t{}.dump().has_value(); +}