Thread overview
[Issue 20167] Issue warning when result discarded from strong pure function?
Aug 26, 2019
Dennis
Aug 26, 2019
Manu
Mar 21, 2021
Nicholas Wilson
Dec 17, 2022
Iain Buclaw
Apr 18, 2023
RazvanN
August 26, 2019
https://issues.dlang.org/show_bug.cgi?id=20167

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dkorpel@live.nl

--- Comment #1 from Dennis <dkorpel@live.nl> ---
(In reply to Manu from comment #0)
> It would be nice to have a compile error (or warning maybe) when the user discards the result from a stong pure function.

```
int f() nothrow pure {
    return 1;
}

void main() {
  f();
}
```

When compiling with -w:

onlineapp.d(6): Warning: calling onlineapp.f without side effects discards
return value of type int, prepend a cast(void) if intentional

Is there anything lacking on the current warning or can this be closed?

--
August 26, 2019
https://issues.dlang.org/show_bug.cgi?id=20167

--- Comment #2 from Manu <turkeyman@gmail.com> ---
Interesting.

I did this same test, but I didn't have `nothrow`.
Why wasn't `nothrow` inferred for this trivial function where the source is as
plain as day to the compiler?

We're meant to be all about attribute inference these days.

--
March 21, 2021
https://issues.dlang.org/show_bug.cgi?id=20167

Nicholas Wilson <iamthewilsonator@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |iamthewilsonator@hotmail.co
                   |                            |m

--- Comment #3 from Nicholas Wilson <iamthewilsonator@hotmail.com> ---
> Why wasn't `nothrow` inferred for this trivial function where the source is as plain as day to the compiler?

FWIW the compiler does inference if the function is a template or the return type is auto: that is

auto f() {
    return 1;
}

and

int f()() {
    return 1;
}

will trigger a warning when compiled with -w

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=20167

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--
April 18, 2023
https://issues.dlang.org/show_bug.cgi?id=20167

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |WORKSFORME

--- Comment #4 from RazvanN <razvan.nitu1305@gmail.com> ---
> I did this same test, but I didn't have `nothrow`.
Why wasn't `nothrow` inferred for this trivial function where the source is as plain as day to the compiler?

We have been discussing about this for a long time, but I don't know if attribute inference is going to be a thing for normal functions. That could be filed as a different issue.

However, this bug report, as Dennis pointed out has nothing actionable.

--