comparison of identical zoned_time objects fails if created in different dll contexts
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.2k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
Pull request #3662 was supposed to fix this issue but it didn't supply the right test case. Here it is. The reason seems to be that .get_time_zone() returns a _TimeZonePtr, so adresses of the pointers are compared instead of the actual data. If the time(zone) was created in a different DLL, then the addresses are not the same even if the time is exactly the same.
Command-line test case
CMakeLists.txt
project(chrono)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_library(chrono-dll SHARED chrono-dll.cpp)
add_executable(chrono-test chrono-test.cpp)
target_link_libraries(chrono-test PUBLIC chrono-dll)
chrono-dll.cpp
#include <chrono>
__declspec(dllexport)
std::chrono::zoned_time<std::chrono::system_clock::duration>
get_zoned_time(std::chrono::system_clock::time_point time) {
return std::chrono::zoned_time<std::chrono::system_clock::duration> {std::chrono::current_zone(), time};
}
chrono-test.cpp
#include <chrono>
#include <iostream>
using namespace std;
using namespace std::chrono;
__declspec(dllimport)
zoned_time<system_clock::duration> get_zoned_time(system_clock::time_point time);
int main() {
using timePoint = zoned_time<system_clock::duration>;
auto now = system_clock::now();
timePoint x {current_zone(), now};
timePoint y = get_zoned_time(now);
cout.setf(cout.boolalpha);
cout << (x == y) << '\n';
}
Result:
C:\git>cmake -B build
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.20348.0 to target Windows 10.0.19042.
-- The C compiler identification is MSVC 19.35.32216.1
-- The CXX compiler identification is MSVC 19.35.32216.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/git/build
C:\git>cmake --build build
MSBuild version 17.5.1+f6fdcf537 for .NET Framework
Checking Build System
Building Custom Rule C:/git/CMakeLists.txt
chrono-dll.cpp
Bibliothek "C:/git/build/Debug/chrono-dll.lib" und Objekt "C:/git/build/Debug/chrono-dll.exp" werden erstellt.
chrono-dll.vcxproj -> C:\git\build\Debug\chrono-dll.dll
Building Custom Rule C:/git/CMakeLists.txt
chrono-test.cpp
chrono-test.vcxproj -> C:\git\build\Debug\chrono-test.exe
Building Custom Rule C:/git/CMakeLists.txt
C:\git>.\build\Debug\chrono-test.exe
false
Expected behavior
I expect to be able to compare zoned times even on different DLLs.
STL version
Microsoft Visual Studio Professional 2022 (64-Bit) - Current
Version 17.5.3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied CMakeLists.txt, chrono-dll.cpp, and chrono-test.cpp reproducer, then inspect zoned_time comparison and get_time_zone handling in the STL implementation. Done means the cross-DLL comparison returns true and the case is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100