proposed @noreturn attribute

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 10 12:58:19 PDT 2017


Jacob Carlborg wrote:

> I'm going to ask the stupid question: I understand that this is for the 
> compiler to generate better code. But, since the attribute (or whatever 
> it is) indicates that a function won't return, it can only be used in 
> very few cases. Are those few cases worth optimizing for?

the case that makes @noreturn worth having is even not optimizing, but 
don't adding visual noise at the call site.

	case Smth: error("boo");
	case Other: ...

oops. i know that `error()` will never return, but compiler doesn't, and 
insisting on adding `break;` there.

sure, i can either put break, or always put `assert(0);` after noreturn 
functions, but hey, aren't we invented computers exactly to lay off such 
borning things onto them!? ;-)


More information about the Digitalmars-d mailing list