What does nothrow buy me?

Max Haughton maxhaton at gmail.com
Tue Oct 27 18:22:48 UTC 2020


On Monday, 26 October 2020 at 18:47:41 UTC, Q. Schroll wrote:
> Obviously, nothrow documents the behavior of a function and is 
> checked when the code is available to the compiler.
>
> At first glance, one could assume a nothrow function can save 
> the compiler from the need to generate exception handling stuff 
> for a function. But since nothrow doesn't mean the function 
> won't throw, but merely that it won't throw an Exception, what 
> optimizations does nothrow enable?

If the compiler doesn't have to think about recovery (i.e. errors 
should result in the program's termination) then the control flow 
analysis and register allocation can be improved. It's hard to 
measure because of the implementation of the function, but you 
can see it in the assembly sometimes.


More information about the Digitalmars-d mailing list