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

Max Haughton maxhaton at gmail.com
Fri Feb 5 14:44:24 UTC 2021


On Friday, 5 February 2021 at 14:09:09 UTC, claptrap wrote:
> On Friday, 5 February 2021 at 11:35:34 UTC, Paul Backus wrote:
>> On Friday, 5 February 2021 at 08:33:21 UTC, claptrap wrote:
>
>> 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
>
> Tbh i didnt even know D had warnings, nor that it warned about 
> unused returns.
>
> Cant see the point with stuff like sqrt() though.

It may alter the state of the floating point unit which may 
effect program behaviour even though you would be thinking "But 
why, I never used it?"


More information about the Digitalmars-d mailing list