tg counter robustness

monkyyy crazymonkyyy at gmail.com
Thu May 29 19:03:49 UTC 2025


People who hate fun, ignore this code, do not report as a bug


```d
enum counter=cast(immutable(void)*)[0].ptr;
auto setcount(int i)=>(*(st(int*)counter))=i;
auto count()=>(*(cast(int*)counter));
auto apply(alias F)(){
	assert(__ctfe);
	enum _=setcount(F(count()));
	return true;
}
int G(int i){
	i+=3;
	i*=i;
	return i;
}
unittest{
	int i;
	i=G(i);
	enum _=apply!G;
	assert(i==count);
}
```

Does there exist a reasonable function `G` that causes this 
unittest to fail?



More information about the Digitalmars-d mailing list