if __ctfe and __ctfe functions
Adam D. Ruppe
destructionator at gmail.com
Tue Jul 29 12:11:03 UTC 2025
On Tuesday, 29 July 2025 at 12:00:02 UTC, Quirin Schroll wrote:
> We could also decide to special-case `if (__ctfe)`, either way:
> The branch in which `__ctfe` is guaranteed to be true should be
> ignored w.r.t. some attribute checks: In a `__ctfe` section,
> - a `@nogc` function can allocate, and
Note that this is implemented in OpenD, it works fine and enables
some interesting pattern when combined with a default parameter
bug fix.
See:
https://dpldocs.info/this-week-in-d/Blog.Posted_2024_11_25.html#to-set-the-stage-for-new-memory-patterns
> - Overloading on `__ctfe` is possible and useful: Overload
> resolution for run-time code generation discards all `__ctfe`
> functions
Same result can be achieved by the if(__ctfe) {} branch....
> - A `__ctfe` function is guaranteed not to be emitted into the
> binary.
this is something opend tried to do via a pragma, but had to
revert since our impl introduced regressions. some day we'll get
back and finish it though.
More information about the dip.ideas
mailing list