vrp bug?

Dukc ajieskola at gmail.com
Mon Aug 31 14:04:57 UTC 2026


On Sunday, 14 June 2026 at 09:06:13 UTC, Kagamin wrote:
> ```
> char BitsToChar(in uint bit5)
> {
> 	const uint b=bit5&0x1f;
> 	return b<10?'0'+b:'a'+(b-10);
> }
> ```
> This code can't implicitly convert to char, but a version 
> without parentheses `'a'+b-10` can. Is this intended or I miss 
> something?

I believe VRP is correctly recognising here `b` can't be more 
than 31, but is missing that the subexpression won't be evaluated 
if it's less than 10.

If I'm right, it's a limitation of value range propagation - Had 
I to choose, I'd say it's not exactly a bug, but I leave it to 
others to judge that.


More information about the Digitalmars-d-learn mailing list