From 817123b9b81d32ceaf9c88bbf78045ab50d7cc2b Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 11 Jun 2021 08:04:12 -0600 Subject: [PATCH] Make an exception text readable. --- include/deal.II/base/exceptions.h | 32 ++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/include/deal.II/base/exceptions.h b/include/deal.II/base/exceptions.h index 5bdeacd668..d5dd3e3962 100644 --- a/include/deal.II/base/exceptions.h +++ b/include/deal.II/base/exceptions.h @@ -1599,6 +1599,27 @@ namespace deal_II_exceptions } #endif /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/ + +namespace deal_II_exceptions +{ + namespace internals + { + /** + * A function that compares two values for equality, after converting to a + * common type to avoid compiler warnings when comparing objects of + * different types (e.g., unsigned and signed variables). + */ + template + inline bool + compare_for_equality(const T &dim1, const U &dim2) + { + using common_type = typename std::common_type::type; + return static_cast(dim1) == static_cast(dim2); + } + } // namespace internals +} // namespace deal_II_exceptions + + /** * Special assertion for dimension mismatch. * @@ -1619,13 +1640,9 @@ namespace deal_II_exceptions * * @ingroup Exceptions */ -#define AssertDimension(dim1, dim2) \ - Assert(static_cast::type)>::type>(dim1) == \ - static_cast::type)>::type>(dim2), \ +#define AssertDimension(dim1, dim2) \ + Assert(::dealii::deal_II_exceptions::internals::compare_for_equality(dim1, \ + dim2), \ dealii::ExcDimensionMismatch((dim1), (dim2))) @@ -1661,6 +1678,7 @@ namespace internal // https://stackoverflow.com/questions/13842468/comma-in-c-c-macro template struct argument_type; + template struct argument_type { -- 2.39.5