Skip to content
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

<chrono>: month::operator++/-- implementation is wrong #63912

Closed
hewillk opened this issue Jul 17, 2023 · 6 comments
Closed

<chrono>: month::operator++/-- implementation is wrong #63912

hewillk opened this issue Jul 17, 2023 · 6 comments
Assignees
Labels
confirmed Verified by a second party libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@hewillk
Copy link
Contributor

hewillk commented Jul 17, 2023

_LIBCPP_HIDE_FROM_ABI inline constexpr month& operator++() noexcept { ++__m_; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month& operator--() noexcept { --__m_; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; }

According to [time.cal.month.members], the result after month increment should be in [1, 12].

#include <chrono>

// only libc++ failed
static_assert(
  [] {
    auto m = std::chrono::December;
    ++m;
    return m.ok();
  }()
);

https://godbolt.org/z/z1d3oM86f

@EugeneZelenko EugeneZelenko added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. and removed new issue labels Jul 17, 2023
@mordante mordante self-assigned this Jul 17, 2023
@mordante mordante added the confirmed Verified by a second party label Jul 17, 2023
@mordante
Copy link
Member

Thanks for the report. The issue also happens when subtracting from January.

@mordante
Copy link
Member

@mordante
Copy link
Member

Landed as ab0d757

@stevem2t
Copy link

year_month::operator+=(month) is broken too...
see https://godbolt.org/z/qds1oE7WM

@philnik777
Copy link
Contributor

@stevem2t Please open a new issue.

@stevem2t
Copy link

@philnik777 created #73162 :-)
Best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed Verified by a second party libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

5 participants