Open gv-me opened 2 years ago
Thank you for your efforts to create a quality bug report.
I do not know what is wrong for sure. However the most common cause of crashes like this result from errors in the build process. The typical error is that tz.cpp is compiled with one set of configuration macros and the client of tz.h is compiled with another. For example USE_OS_TZDB
may be set to 1 in one translation unit and 0 in another.
Can you explore this possibility? Meanwhile I will be reexamining date's streaming code. Thanks.
Thanks for your quick response. I am using the following code to include date library:
set( USE_SYSTEM_TZ_DB ON CACHE INTERNAL "")
set( ENABLE_DATE_TESTING OFF CACHE INTERNAL "")
set( BUILD_TZ_LIB ON CACHE INTERNAL "")
add_subdirectory(<path to library>/date date EXCLUDE_FROM_ALL)
This should enable the options across the entire date/CMakeLists.txt
. I am even getting the following print in CMake.
# date: USE_SYSTEM_TZ_DB ON
For those clients that include tz.h, do they also set USE_SYSTEM_TZ_DB ON
?
the consumer projects link to a library (which links to date::date-tz
) they don't set any compile definitions themselves.
Something like this.
# libA/CMakeLists.txt
set( USE_SYSTEM_TZ_DB ON CACHE INTERNAL "")
set( ENABLE_DATE_TESTING OFF CACHE INTERNAL "")
set( BUILD_TZ_LIB ON CACHE INTERNAL "")
add_subdirectory(<path to library>/date date EXCLUDE_FROM_ALL)
add_library(liba ... ... ...)
target_link_libraries(liba date::date-tz)
# execB/CMakeLists.txt
add_subdirectory(<path to library>/libA libA )
add_executable(execb dateuser.cpp ..)
target_link_libraries(execb liba)
// dateuser.cpp
#include "date/date.h"
#include "date/tz.h"
std::string format_time(const TimePoint tp, const std::string& formatString) {
const auto zoned = date::make_zoned(date::current_zone(), date::floor<millis>(tp));
return date::format(formatString, zoned);
}
Should the execB also have some compile definitions set for this? I imagine this might be changing the way preprocessor directives are including/excluding code in date.h
and tz.h
okay so I just did a quick check and it seems that the tz.h
included from the second project does also have USE_OS_TZDB
set.
Adding this at the top of tz.h
and date.h
does not fire an error
#ifndef USE_OS_TZDB
# error "USE_OS_TZDB is not set!"
#endif
Summary:
We use
date::format
function to get formatted timestamp in one of our internal libraries. We encountered a segmentation fault in function call todate::format()
when%T
formatter is used anywhere in the format string.System details:
Release
orRelWithDebInfo
add_subdirectory()
call in cmakeCrash details:
the crash occurs in this code snippet:
Stack trace on the latest commit e6f4aed4d11d4e50687e9aa8630c7f0db7d31dba is given below:
I am unable to reproduce the bug outside out the build environment and cmake projects that we use.