diff --git a/wpimath/src/main/native/include/units/base.h b/wpimath/src/main/native/include/units/base.h index bc9fb446f73..eba34998313 100644 --- a/wpimath/src/main/native/include/units/base.h +++ b/wpimath/src/main/native/include/units/base.h @@ -2328,7 +2328,7 @@ namespace units // unary addition: +T template class NonLinearScale> - inline unit_t operator+(const unit_t& u) noexcept + constexpr inline unit_t operator+(const unit_t& u) noexcept { return u; } @@ -2352,7 +2352,7 @@ namespace units // unary addition: -T template class NonLinearScale> - inline unit_t operator-(const unit_t& u) noexcept + constexpr inline unit_t operator-(const unit_t& u) noexcept { return unit_t(-u()); } diff --git a/wpimath/src/test/native/cpp/UnitsTest.cpp b/wpimath/src/test/native/cpp/UnitsTest.cpp index d5ba717e878..6f70d83a7eb 100644 --- a/wpimath/src/test/native/cpp/UnitsTest.cpp +++ b/wpimath/src/test/native/cpp/UnitsTest.cpp @@ -3063,14 +3063,17 @@ TEST_F(Constexpr, construction) { constexpr meter_t result0(0); constexpr auto result1 = make_unit(1); constexpr auto result2 = meter_t(2); + constexpr auto result3 = -3_m; EXPECT_EQ(meter_t(0), result0); EXPECT_EQ(meter_t(1), result1); EXPECT_EQ(meter_t(2), result2); + EXPECT_EQ(meter_t(-3), result3); EXPECT_TRUE(noexcept(result0)); EXPECT_TRUE(noexcept(result1)); EXPECT_TRUE(noexcept(result2)); + EXPECT_TRUE(noexcept(result3)); } TEST_F(Constexpr, constants) {