assert and static assert and code generation
Cecil Ward
cecil at cecilward.com
Wed Jun 14 13:00:39 UTC 2023
The compilers should surely be able to use the presence of static
asserts to enable better code generation since the direction of
some later conditional branches can be known, value ranges can be
known, all kinds of potential good stuff. Is that correct?
If assert without the static is implemented as debug assert then
unless the compiler makes an exception and does not all the
‘debug’-conditional to simply wipe out the assert entirely the
compiler won’t gain the benefit of the information available from
an assert.
There is of course the difficulty that the non-static assert can
not (necessarily) be evaluated at compile-time. But of course the
_bool value_ of the assert text-expression is always known.
Is there a way of testing whether or not something can be
evaluated at compile-time or really requires run-time evaluation?
If so, is it something we could use routinely? I could really use
this in certain templates, for the case where there are several
specialisations that use parameters with special constant values
and then there is the ‘otherwise’ default expansion of the
template, which has an argument that is not a known compile-time
constant.
So could non-static asserts that do not in fact require run-time
evaluation be convertible to an effective status assert, with all
the benefits possible in code generation?
More information about the Digitalmars-d
mailing list