template warning message that will *never* effect compilation

monkyyy crazymonkyyy at gmail.com
Sat Feb 15 23:45:47 UTC 2025


On Saturday, 15 February 2025 at 22:00:40 UTC, Walter Bright 
wrote:
> I suspect `pragma(msg, "informative message")` will work for 
> that.

```d
import std;
struct filter{
	void popFront(){}
	enum empty=true;
	int length()(){//fake length, to provode warning message on use
		pragma(msg, "informative message");
		static assert(0);
	}
}
int count(R)(R r){
	int i;
	while(! r.empty){
		i++;
		r.popFront;
	}
	return i;
}
int lengthorcount(R)(R r){//calls length if aviable, otherwise 
count
	static if(__traits(compiles,r.length)){
		return r.length;
	} else {
		return r.count;
}}

unittest{
	int count=filter().count;
	count=filter().lengthorcount;//fails
}
```

it will effect compilation


More information about the dip.ideas mailing list