diff --git a/README-maintainer.md b/README-maintainer.md index 73c5efd..3da387a 100644 --- a/README-maintainer.md +++ b/README-maintainer.md @@ -209,6 +209,11 @@ Building docs from pull requests is also enabled. This requires inclusion of 'assert_debug.h' or 'Util.hh'. Remember that these (except for 'qpdf_static_expect') are only checked in debug builds. + * Use 'util::assertion' when checks should also be carried out in + release code in preference to throwing logic_errors directly + unless it is practical and desirable to test violations during + CI testing. This avoids obscuring genuine gaps in coverage with + noise generated by unreachable sanity checks. These rules are enforced by the check-assert test. This practices serves to diff --git a/libqpdf/qpdf/Util.hh b/libqpdf/qpdf/Util.hh index d641e9c..d812fdf 100644 --- a/libqpdf/qpdf/Util.hh +++ b/libqpdf/qpdf/Util.hh @@ -3,6 +3,7 @@ #include +#include #include #include @@ -12,6 +13,17 @@ namespace qpdf::util // inline functions, some of which are exposed as regular functions in QUtil. Implementations // are in QUtil.cc. + // Throw a logic_error if 'cond' does not hold. + // + // DO NOT USE unless it is impractical or unnecessary to cover violations during CI Testing. + inline void + assertion(bool cond, std::string const msg) + { + if (!cond) { + throw std::logic_error(msg); + } + } + inline constexpr char hex_decode_char(char digit) {