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

durations of floating point type or smaller than long long cause "conditional expression is constant" on MSVC #2854

Closed
lefticus opened this issue Apr 7, 2022 · 1 comment
Labels

Comments

@lefticus
Copy link
Contributor

lefticus commented Apr 7, 2022

/W4 is required. Seems to happen in any version of {fmt}, cannot reproduce in GCC or Clang

They appear to be similar but unrelated warnings.

Here is a minimal repro:

https://compiler-explorer.com/z/Yve79WaTf

#include <fmt/format.h>
#include <fmt/chrono.h>
#include <chrono>

int main()
{
  // this works
  //using milliseconds = std::chrono::duration<long long, std::milli>;

  // but this does not
  //using milliseconds = std::chrono::duration<int, std::milli>;

  // and neither does this
  using milliseconds = std::chrono::duration<double, std::milli>;

  fmt::print("ms {}", milliseconds{});
}

Warning stems from this line:

fmt/include/fmt/chrono.h

Lines 246 to 260 in d141cdb

if (Factor::num != 1) {
constexpr auto max1 = detail::max_value<IntermediateRep>() /
static_cast<IntermediateRep>(Factor::num);
if (count > max1) {
ec = 1;
return {};
}
constexpr auto min1 = std::numeric_limits<IntermediateRep>::lowest() /
static_cast<IntermediateRep>(Factor::num);
if (count < min1) {
ec = 1;
return {};
}
count *= static_cast<IntermediateRep>(Factor::num);
}

and this line:

fmt/include/fmt/chrono.h

Lines 82 to 87 in d141cdb

if (F::digits > T::digits &&
from > static_cast<From>(detail::max_value<To>())) {
ec = 1;
return {};
}
}

@vitaut
Copy link
Contributor

vitaut commented Apr 8, 2022

AFAICS this has been fixed in #2518 already.

@vitaut vitaut closed this as completed Apr 8, 2022
@vitaut vitaut added the invalid label Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants