Skip to content

Explicitly include <chrono> #13537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2024
Merged

Explicitly include <chrono> #13537

merged 1 commit into from
Nov 24, 2024

Conversation

StephanTLavavej
Copy link
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:

auto realtime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();

src/backend.cpp includes platform/uvc-device.h which includes <thread>:

#include "platform/uvc-device.h"

#include <thread>

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:

std::this_thread::sleep_for( std::chrono::milliseconds( DELAY_FOR_RETRIES ) );

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
Collaborator

Can one of the admins verify this patch?

@Nir-Az
Copy link
Collaborator

Nir-Az commented Nov 24, 2024

@StephanTLavavej Thanks for the fix.

@Nir-Az Nir-Az merged commit f59e26d into IntelRealSense:development Nov 24, 2024
22 checks passed
@StephanTLavavej StephanTLavavej deleted the include-chrono branch November 24, 2024 07:04
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