Skip to content

Commit

Permalink
Fix type comparison for C++20
Browse files Browse the repository at this point in the history
The two are effectively different types and there is nothing which allows
implicitly casting between them. Also add some protection making sure we notice
if we change one of the two sides inadvertedly.
  • Loading branch information
ktf committed Oct 27, 2023
1 parent 591c0f0 commit afcd4da
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions DataFormats/Headers/include/Headers/TimeStamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,14 @@ class TimeStamp
static_assert(std::is_same<typename T::rep, Rep>::value && std::is_same<typename T::period, Period>::value,
"only clock and duration types defining the rep and period member types are allowed");
using duration = std::chrono::duration<Rep, Period>;
if (mUnit == sClockLHC) {
static_assert(sizeof(mUnit) == sizeof(sClockLHC), "size mismatch of mUnit and sClockLHC");
if (memcmp(&mUnit, &sClockLHC, sizeof(sClockLHC)) == 0) {
// cast each part individually, if the precision of the return type
// is smaller the values are simply truncated
return std::chrono::duration_cast<duration>(LHCOrbitClock::duration(mPeriod) + LHCBunchClock::duration(mBCNumber));
}
if (mUnit == sMicroSeconds) {
static_assert(sizeof(mUnit) == sizeof(sMicroSeconds), "size mismatch of mUnit and sMicroSeconds");
if (memcmp(&mUnit, &sMicroSeconds, sizeof(sMicroSeconds)) == 0) {
// TODO: is there a better way to mark the subticks invalid for the
// micro seconds representation? First step is probably to remove/rename the
// variable
Expand Down

0 comments on commit afcd4da

Please sign in to comment.