Thread overview
template warning message that will *never* effect compilation
Feb 04
monkyyy
Feb 15
monkyyy
Feb 17
monkyyy
February 04

Contracts, the ooness of std.range.interfaces, several traits are about attempting to control the correctness of templates; I say all'y'alls should give it all up entirely make the dumbest thing possible. However such code will make terrible, terrible template error messages, the more used and nested, the worse those error message get

If you add dumby functions currently it will effect trait compiles

import std;
void foo()(){
	static assert(0,"foo is fundmentally incorrect, consider using bar instead");
}
void callifpossible(alias F)(){
	static if(__traits(compiles,F)){
		F();
	} else {
		"WARN: this didnt actaully compile, but managed to run".writeln;
	}}
unittest{
	callifpossible!foo;//fails
}

Suppose you wanted to add a warning to filter that length "cant be defined, consider adding something that caches the output", that function will likely work like foo from that example code and by having it there your interducing interspersion liability's and generate new exciting problems.


struct filter{
  throw template length() "filter.length can not be defined";
}

add it behind a verbose compile flag, define such code as unable to effect compilation; maybe it will make template hell have better error messages

February 15
I suspect `pragma(msg, "informative message")` will work for that.
February 15
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
February 17
You can also add a message to the `static assert(0, "informative message")`
February 17
On Monday, 17 February 2025 at 08:24:51 UTC, Walter Bright wrote:
> You can also add a message to the `static assert(0, "informative message")`

which will also effect compilation