Skip to content

Commit

Permalink
Fix compile error under GCC-12
Browse files Browse the repository at this point in the history
Fix ambiguous parse error in the following expression:
  if constexpr (PiRatio::num / PiRatio::den < 1 && PiRatio::num / PiRatio::den > -1)

GCC-12 apparently interprets `PiRatio::den < 1 && PiRatio::num /
PiRatio::den >` as a template expression, which it shouldn't. Help
disambiguating this expression by putting parentheses around the
division.

Closes #306
  • Loading branch information
krf authored and nholthaus committed Mar 3, 2023
1 parent c48caa1 commit da6dd91
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/units/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@ namespace units
normal_convert(static_cast<CommonUnderlying>(value) / static_cast<CommonUnderlying>(pow(detail::PI_VAL, -PiRatio::num / PiRatio::den))));
}
// non-constexpr pi in numerator. This case (only) isn't actually constexpr.
else if constexpr (PiRatio::num / PiRatio::den < 1 && PiRatio::num / PiRatio::den > -1)
else if constexpr ((PiRatio::num / PiRatio::den) < 1 && (PiRatio::num / PiRatio::den) > -1)
{
return static_cast<To>(normal_convert(
static_cast<CommonUnderlying>(value) * static_cast<CommonUnderlying>(std::pow(detail::PI_VAL, PiRatio::num / PiRatio::den))));
Expand Down

0 comments on commit da6dd91

Please sign in to comment.