nholthaus / units

a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.
http://nholthaus.github.io/units/
MIT License
934 stars 134 forks source link

Does not compile with GCC 12 #306

Closed StefanoD closed 1 year ago

StefanoD commented 1 year ago

Please include the following information in your issue:

  1. Which version of units you are using 3.x Commit 2b2c063c87f934af79ae67006c35a9350d1b4a0a (which is a older one, but the latest commit has the same problem)

  2. Which compiler exhibited the problem (including compiler version)

GCC 12.

units/include/units/core.h:1875:68: error: expected ‘template’ keyword before dependent template name [-Werror=missing-template-keyword] 1875 else if constexpr (PiRatio::num / PiRatio::den < 1 && PiRatio::num / PiRatio::den > -1)

The patch for the mentioned commit is:

diff --git a/units/include/units/core.h b/units/include/units/core.h
index 02629183e..2cb5db054 100644
--- a/units/include/units/core.h
+++ b/units/include/units/core.h
@@ -1872,7 +1872,7 @@ namespace units
                                        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))));
@@ -4041,4 +4041,4 @@ namespace std
// c-basic-offset: 2
// fill-column: 116
// tab-width: 4
-// End:
\ No newline at end of file
+// End:
krf commented 1 year ago

Fixed in v3.x branch. Not sure there should be back port to master.