]> git.ipfire.org Git - thirdparty/squid.git/commit
Replace defective Must2(c, "not c") API (#785)
authorAlex Rousskov <rousskov@measurement-factory.com>
Tue, 16 Mar 2021 06:23:02 +0000 (06:23 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Tue, 16 Mar 2021 06:23:06 +0000 (06:23 +0000)
commit2bde9c7cec0d243d5b1e73b19da19ef0a5d8a08a
tree97d0483d668e3682ed834911e5f4d44d79327216
parent1e6ceb8f5af3e7af2d4b08c64bdd56c83e5d1cd7
Replace defective Must2(c, "not c") API (#785)

... with Must3(c, "c", Here())

* We should not make a Must*() API different from the standard C++
  static_assert() API. It is just too confusing, especially since the
  two calls are very closely related.

* We should not tell Must*() writers to specify one condition (i.e. what
  must happen) but then describe the opposite condition (i.e. what went
  wrong). When the text describes the opposite condition, it is easy for
  a human writing or thinking about the text to type the wrong
  condition: Must2(got < need, "incomplete message") looks correct!

We should not keep the same macro name when changing the meaning of the
second parameter. Fortunately, adding a third argument to the macro fits
nicely into how modern Squid code should pass the source code location.

Must3() does not support SBuf descriptions. I tried to support them, but
doing so without duplicating non-trivial code is too difficult, and
since the current code does not actually use them, wasteful.

If future (complex) code needs SBuf conditions, then it should probably
use an explicit throw statement instead, especially since Must*() is,
like assert(), supposed to quickly check source code sanity rather than
validate unsafe input. A compile-time condition description and the
source code location is usually enough for sanity checks, while proper
reporting of invalid input usually also requires parsing context info.
scripts/calc-must-ids.pl
src/base/TextException.h
src/sbuf/SBuf.cc