Discussion Thread: DIP 1038-- at nodiscard--Final Review

Paul Backus snarwin at gmail.com
Fri Feb 5 11:35:34 UTC 2021


On Friday, 5 February 2021 at 08:33:21 UTC, claptrap wrote:
> Are you going to annotate every function that has a return 
> value and no side effects? All the math functions, min, max, 
> sqrt? I mean is there a difference between "the point of the 
> function is its return value", and "if you dont handle the 
> return value bad things will happen", and nodisgard is for the 
> latter?

Remember that the compiler already produces a warning (not an 
error) if you discard the return value of a `pure nothrow` 
function, which includes most std.math functions:

     void main()
     {
         import std.math;
         sqrt(2.0);
     }

Compile with `dmd -wi` and you get:

onlineapp.d(4): Warning: calling std.math.sqrt without side 
effects discards return value of type double, prepend a 
cast(void) if intentional

https://run.dlang.io/is/cE80Uv


More information about the Digitalmars-d mailing list