Skip to content

Commit

Permalink
fix: clang is too stupid to provide a deprecation warning for `text_e…
Browse files Browse the repository at this point in the history
…ncoding`
  • Loading branch information
mpusz committed Nov 21, 2024
1 parent c745e90 commit 0c09008
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
11 changes: 8 additions & 3 deletions src/core/include/mp-units/framework/dimension.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,18 @@ template<std::intmax_t Num, std::intmax_t Den = 1, Dimension D>
[[nodiscard]] consteval Dimension auto cbrt(Dimension auto d) { return pow<1, 3>(d); }


MP_UNITS_DIAGNOSTIC_PUSH
MP_UNITS_DIAGNOSTIC_IGNORE_DEPRECATED
struct dimension_symbol_formatting {
#if MP_UNITS_COMP_CLANG
// TODO prevents the deprecated usage in implicit copy constructor warning
character_set char_set = character_set::default_character_set;
#else
[[deprecated("Use `char_set` instead")]] character_set encoding = character_set::default_character_set;
MP_UNITS_DIAGNOSTIC_PUSH
MP_UNITS_DIAGNOSTIC_IGNORE_DEPRECATED
character_set char_set = encoding;
MP_UNITS_DIAGNOSTIC_POP
#endif
};
MP_UNITS_DIAGNOSTIC_POP

MP_UNITS_EXPORT_END

Expand Down
11 changes: 8 additions & 3 deletions src/core/include/mp-units/framework/unit_symbol_formatting.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,20 @@ enum class unit_symbol_separator : std::int8_t {
default_separator = space
};

MP_UNITS_DIAGNOSTIC_PUSH
MP_UNITS_DIAGNOSTIC_IGNORE_DEPRECATED
struct unit_symbol_formatting {
#if MP_UNITS_COMP_CLANG
// TODO prevents the deprecated usage in implicit copy constructor warning
character_set char_set = character_set::default_character_set;
#else
[[deprecated("Use `char_set` instead")]] character_set encoding = character_set::default_character_set;
MP_UNITS_DIAGNOSTIC_PUSH
MP_UNITS_DIAGNOSTIC_IGNORE_DEPRECATED
character_set char_set = encoding;
MP_UNITS_DIAGNOSTIC_POP
#endif

unit_symbol_solidus solidus = unit_symbol_solidus::default_denominator;
unit_symbol_separator separator = unit_symbol_separator::default_separator;
};
MP_UNITS_DIAGNOSTIC_POP

} // namespace mp_units
8 changes: 4 additions & 4 deletions test/runtime/fmt_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ using v = cartesian_vector<double>;

TEST_CASE("dimension_symbol", "[dimension][symbol]")
{
using enum text_encoding;
using enum character_set;

std::ostringstream os;

Expand All @@ -67,14 +67,14 @@ TEST_CASE("dimension_symbol", "[dimension][symbol]")

SECTION("Portable mode")
{
os << dimension_symbol<dimension_symbol_formatting{.encoding = portable}>(isq::power.dimension);
os << dimension_symbol<dimension_symbol_formatting{.char_set = portable}>(isq::power.dimension);
CHECK(os.str() == "L^2MT^-3");
}
}

TEST_CASE("unit_symbol", "[unit][symbol]")
{
using enum text_encoding;
using enum character_set;
using enum unit_symbol_solidus;
using enum unit_symbol_separator;

Expand All @@ -88,7 +88,7 @@ TEST_CASE("unit_symbol", "[unit][symbol]")

SECTION("Portable mode")
{
os << unit_symbol<unit_symbol_formatting{.encoding = portable}>(m / s2);
os << unit_symbol<unit_symbol_formatting{.char_set = portable}>(m / s2);
CHECK(os.str() == "m/s^2");
}

Expand Down

0 comments on commit 0c09008

Please sign in to comment.