new annotation or pragma to mark functions that are intended to be only used during compile time

Stefan Koch uplink.coder at googlemail.com
Sat Feb 22 07:04:19 UTC 2025


On Friday, 21 February 2025 at 01:14:50 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> On 21/02/2025 1:38 PM, Richard (Rikki) Andrew Cattermole wrote:
>> [...]
>
> Not possible.
>
> assert gets processed during semantic 3, but things like 
> variable declarations are seen during semantic 2.
>
> It has to be an attribute seeable on the function declaration.
>
> ```d
> extern(C) void main() {
> 	__gshared global = func; // Error: cannot use non-constant 
> CTFE pointer in an initializer `func()
> 	func; // Error: undefined reference to `void start.func()`
> }
>
> int* func() {
> 	assert(__ctfe);
> 	return new int;
> }
> ```

You might want to look at my 4 years old PR:|
https://github.com/dlang/dmd/pull/11007/files


More information about the dip.ideas mailing list