`STL.natvis`: Fixed `time_point` visualization of year off-by-one by pzychotic · Pull Request #5389 · microsoft/STL · GitHub
Skip to content

STL.natvis: Fixed time_point visualization of year off-by-one#5389

Merged
StephanTLavavej merged 1 commit into
microsoft:mainfrom
pzychotic:natvis-time_point
Apr 10, 2025
Merged

STL.natvis: Fixed time_point visualization of year off-by-one#5389
StephanTLavavej merged 1 commit into
microsoft:mainfrom
pzychotic:natvis-time_point

Conversation

@pzychotic

Copy link
Copy Markdown
Contributor

When the time_point is sometime in February, the debugger visualization of the year will be off-by-one.

You can test this with this little snippet:

#include <chrono>
#include <iostream>

int main()
{
    using namespace std::chrono;

    constexpr year_month_day ymd = 2025y / 2 / 15;
    constexpr system_clock::time_point tp = sys_days{ ymd };
    std::cout << ymd << " | " << tp << std::endl;
}

The console output will be correct:
2025-02-15 | 2025-02-15 00:00:00.0000000

But the debugger shows a year of 2024 for tp:
Screenshot 2025-04-02 210521

As per the referenced calculation used to construct the debugger visualization, the year should be calculated by this formula:
const Int y = static_cast<Int>(yoe) + era * 400; ... (y + (m <= 2)

But the nativs contains this:
<Intrinsic Name="year" Expression="((long long)yoe()) + era() * 400 + (month() &lt; 2)"/>

Missing the = sign in the less-than-or-equal 2 check.

When the `time_point` is sometime in February, the debugger visualization of the year will be off-by-one.
@pzychotic pzychotic requested a review from a team as a code owner April 2, 2025 19:19
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Apr 2, 2025
@StephanTLavavej StephanTLavavej added bug Something isn't working visualizer How the VS debugger displays STL types labels Apr 2, 2025
@StephanTLavavej

Copy link
Copy Markdown
Member

@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in STL Code Reviews Apr 2, 2025
@Nerixyz

Nerixyz commented Apr 2, 2025

Copy link
Copy Markdown
Contributor

Thank you for noticing and fixing this!

@StephanTLavavej StephanTLavavej moved this from Ready To Merge to Merging in STL Code Reviews Apr 9, 2025
@StephanTLavavej StephanTLavavej self-assigned this Apr 9, 2025
@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit d005527 into microsoft:main Apr 10, 2025
@github-project-automation github-project-automation Bot moved this from Merging to Done in STL Code Reviews Apr 10, 2025
@StephanTLavavej

StephanTLavavej commented Apr 10, 2025

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working visualizer How the VS debugger displays STL types

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants