Skip to content

Explicitly include <chrono> - #13537

Merged
Nir-Az merged 1 commit into
realsenseai:developmentfrom
StephanTLavavej:include-chrono
Nov 24, 2024
Merged

Explicitly include <chrono>#13537
Nir-Az merged 1 commit into
realsenseai:developmentfrom
StephanTLavavej:include-chrono

Conversation

@StephanTLavavej

Copy link
Copy Markdown
Contributor

I work on Microsoft Visual C++, where we regularly build popular open-source projects, including yours, with development builds of our compiler and libraries to detect and prevent shipping regressions that would affect you. This also allows us to provide advance notice of breaking changes, which is the case here.

I just merged microsoft/STL#5105, which revealed a conformance issue in librealsense.

Compiler error with this STL change:

C:\gitP\IntelRealSense\librealsense\src\backend.cpp(56,88): error C2039: 'system_clock': is not a member of 'std::chrono'

Affected code:
https://github.com/IntelRealSense/librealsense/blob/a75366ff9e40e765993b15ad6f18b45200616a73/src/backend.cpp#L56

src/backend.cpp includes platform/uvc-device.h which includes <thread>:
https://github.com/IntelRealSense/librealsense/blob/a75366ff9e40e765993b15ad6f18b45200616a73/src/backend.cpp#L19
https://github.com/IntelRealSense/librealsense/blob/a75366ff9e40e765993b15ad6f18b45200616a73/src/platform/uvc-device.h#L18

This was assuming that including <thread> makes the chrono::system_clock type available, which is not guaranteed by the Standard. You must explicitly include <chrono>.

platform/uvc-device.h itself uses chrono::milliseconds:
https://github.com/IntelRealSense/librealsense/blob/a75366ff9e40e765993b15ad6f18b45200616a73/src/platform/uvc-device.h#L194

While MSVC's STL still has <thread> dragging in chrono::milliseconds, this is also not guaranteed by the Standard. Therefore, the proper change is to include <chrono> in platform/uvc-device.h.

@sysrsbuild

Copy link
Copy Markdown
Contributor

Can one of the admins verify this patch?

@Nir-Az

Nir-Az commented Nov 24, 2024

Copy link
Copy Markdown
Collaborator

@StephanTLavavej Thanks for the fix.

@Nir-Az
Nir-Az merged commit f59e26d into realsenseai:development Nov 24, 2024
@StephanTLavavej
StephanTLavavej deleted the include-chrono branch November 24, 2024 07:04
@BillyONeal BillyONeal mentioned this pull request Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants