From 013c34392901f37c3591f6e09e1a02bd323b1569 Mon Sep 17 00:00:00 2001 From: Chip Hogg Date: Mon, 4 Dec 2023 13:49:12 -0500 Subject: [PATCH] Stop shadowing `ONE` (#205) Our loosening of the overflow safety surface introduced a warning, which is prominently visible on our [canonical godbolt link]: ![image](https://github.com/aurora-opensource/au/assets/1819744/d55ef99f-7073-4644-9ffc-f75fa3893441) Oops! We shadowed the _magnitude_ `ONE` (globally available in the library) with the _constant_ `ONE`. The quick fix is to rename the newcomer (which is not publicly visible anyway) to `UNITY`. To prevent this problem from recurring, we also add `-Wshadow` to our regular compiler options. [canonical godbolt link]: https://godbolt.org/z/KrvfhP4M3 --- au/math.hh | 8 ++++---- build/copts.bzl | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/au/math.hh b/au/math.hh index f71204e9..34a194c3 100644 --- a/au/math.hh +++ b/au/math.hh @@ -238,8 +238,8 @@ constexpr auto int_pow(Quantity q) { template constexpr auto inverse_in(TargetUnits target_units, Quantity q) { using Rep = std::common_type_t; - constexpr auto ONE = make_constant(UnitProductT<>{}); - return static_cast(ONE.in(associated_unit(target_units) * U{}) / q.in(U{})); + constexpr auto UNITY = make_constant(UnitProductT<>{}); + return static_cast(UNITY.in(associated_unit(target_units) * U{}) / q.in(U{})); } // @@ -270,10 +270,10 @@ constexpr auto inverse_in(TargetUnits target_units, Quantity q) { // This will fail at compile time for types that can't hold 1'000'000. constexpr R threshold = 1'000'000; - constexpr auto ONE = make_constant(UnitProductT<>{}); + constexpr auto UNITY = make_constant(UnitProductT<>{}); static_assert( - ONE.in(associated_unit(target_units) * U{}) >= threshold || + UNITY.in(associated_unit(target_units) * U{}) >= threshold || std::is_floating_point::value, "Dangerous inversion risking truncation to 0; must supply explicit Rep if truly desired"); diff --git a/build/copts.bzl b/build/copts.bzl index 63b82571..f1147cf1 100644 --- a/build/copts.bzl +++ b/build/copts.bzl @@ -30,6 +30,7 @@ BASE_CLANG_COPTS = [ # Diagnostics "-fcolor-diagnostics", "-Wall", + "-Wshadow", "-Wthread-safety", "-Wself-assign", ]