February 05, 2021
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.
February 05, 2021
On Friday, 5 February 2021 at 14:09:09 UTC, claptrap wrote:
> Tbh i didnt even know D had warnings, nor that it warned about unused returns.

You would have learned if you'd read the DIP all the way through. ;)

https://github.com/dlang/DIPs/blob/ab056150975a9a8db5b5da3dbffdd81529802a49/DIPs/DIP1038.md#in-d

> Cant see the point with stuff like sqrt() though.

It's a generic warning that applies to any discarded expression without side effects. For example, it will also trigger if you write

    1 + 1;
February 05, 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?"
February 05, 2021
On Friday, 5 February 2021 at 14:16:22 UTC, Paul Backus wrote:
> On Friday, 5 February 2021 at 14:09:09 UTC, claptrap wrote:
>> Tbh i didnt even know D had warnings, nor that it warned about unused returns.
>
> You would have learned if you'd read the DIP all the way through. ;)

Touche'

:)
February 05, 2021
On Friday, 5 February 2021 at 14:16:22 UTC, Paul Backus wrote:
> On Friday, 5 February 2021 at 14:09:09 UTC, claptrap wrote:
>> Cant see the point with stuff like sqrt() though.
>
> It's a generic warning that applies to any discarded expression without side effects. For example, it will also trigger if you write
>
>     1 + 1;

That one's an outright error (without -wi) because if you replace the 1s with identifiers, and + with *, you get a parsing ambiguity (in C, too):
https://theartofmachinery.com/2020/08/18/d_declarations_for_c_programmers.html#syntax-ambiguities
1 2
Next ›   Last »