From: Wolfgang Bangerth Date: Fri, 11 Jun 2021 14:04:12 +0000 (-0600) Subject: Make an exception text readable. X-Git-Tag: v9.4.0-rc1~1230^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F12442%2Fhead;p=dealii.git Make an exception text readable. --- 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 {