[Bug c/66425] (void) cast doesn't suppress __attribute__((warn_unused_result))

2023-08-17 Thread romato.san1337 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425

--- Comment #59 from Roman Krotov  ---
(In reply to Ed Catmur from comment #58)
> (In reply to Roman Krotov from comment #57)
I already addressed all of it in my previous 2 comments...
I'll write more clearly then.

> > But I don't see any reasons not to implement the switch right now...
> Making [[gnu::warn_unused_result]] mean the same as [[nodiscard]] would be a
> reduction in expressivity.
All, what I'm asking for, is to make something like -Wno-void-unused, which
would suppress the warnings only for the (void) casted calls.
This is desperately needed by the projects like systemd (see the first link in
my first comment) as a less severe variant than -Wno-unused-result, so that
they won't get punished with less diagnostics.

In fact, gcc already has a "not recommended non-default" switch model:
  -Wno-coverage-mismatch
<...>   -Wno-coverage-mismatch  can  be  used  to  disable  the warning
<...> disabling the warning is not recommended.

I don't see any reason not to implement -Wno-void-unused with the similar
description (stating that it's not recommended, if you want) to help the
projects like systemd.
It won't change the meaning of the wur attribute, bacause it will be a
non-default switch.

> > what about the projects
> > what don't agree with the distinction of these 2 attributes? Or just want to
> > be more compatible with clang?
> They can use [[nodiscard]].
> 
> > Or they just may not agree with the choice of a library, that decided to put
> > wur instead of nodiscard for a specific function.
> Then they can write their own wrappers using [[nodiscard]].
What about libraries and programs that will prefer to stay on C99/C11 (without
C2x extensions), especially if they use -pedantic?
Even if there will be something like __attribute__(nodiscard),
What about programs and libraries that will not prefer to update?
That's why we shouldn't rely on the future and should implement the solution
now.

[Bug c/66425] (void) cast doesn't suppress __attribute__((warn_unused_result))

2023-08-10 Thread romato.san1337 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425

--- Comment #57 from Roman Krotov  ---
(In reply to Ed Catmur from comment #55)
> So this problem will resolve itself, over time.

But I don't see any reasons not to implement the switch right now...
Late is better than never.

> we can expect that attribute to be adopted where people intend that behavior
> as opposed to the
> warning not suppressible by cast to void

I see your point and I partially agree with it, but what about the projects
what don't agree with the distinction of these 2 attributes? Or just want to be
more compatible with clang?
Or they just may not agree with the choice of a library, that decided to put
wur instead of nodiscard for a specific function.
Something like -Wno-void-unused would still be better for them than
-Wno-unused-result, for the reasons in my previous comment.

(In reply to Martin Uecker from comment #56)
> works as expected and is supported for older language modes

Even if one day projects, that will prefer to stay on C99 or C11 and use
-Wpedantic (which warns about [[]] right now), will be able to use [[syntax]]
without any warning, they may still not like it. Even if gcc will include
nodiscard into the __attribute__ syntax, there, for sure, will be the libraries
that won't prefer to update or use the new attribute.
For these situations, or even if they **will** use the new attribute, see my
previous paragraph.

[Bug c/66425] (void) cast doesn't suppress __attribute__((warn_unused_result))

2023-08-09 Thread romato.san1337 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425

Roman Krotov  changed:

   What|Removed |Added

 CC||romato.san1337 at gmail dot com

--- Comment #54 from Roman Krotov  ---
I'm also very frustrated about this behavior, but I'm not asking to **change**
it. I see your point and, although I think it's severely outdated now, I
respect your decision.

Instead I'm offering a compromise, or to better describe it, a win-win
solution.
What about introducing something like `-Wno-void-unused`, which would only
disable the warnings for the (void) casted calls?

And I'm not asking to do it for me, or some other random dudes; do it for
systemd, they are also very frustrated about this:
https://github.com/systemd/systemd/blob/5a96b32dead5132ba37a8b968c59101c2aac8d23/meson.build#L400

That's because they use (void) casts very frequently:
https://github.com/search?q=repo%3Asystemd%2Fsystemd+language%3AC+%22%28void%29%22=code

You can probably say they are in the wrong by doing the bad practice and should
do a macro instead.
And you may be right. I really appreciate your commitment to teach people good
practices, but **suggesting** them (by setting the default behavior which
**recommends** the programmers to use these practices) should be enough.
I don't think it's a good idea to **force** people to use them, by either
spamming them with warnings (useless to them, because they already made a
decision) or making them disable such warnings altogether, which could lead
them to miss a bug where they forgot to use a value of a function (which they
didn't cast with void).

You may say it's their fault, but let me ask you a question, who is winning
from the current situation? Certainly, not you, because you didn't convince
them to change, instead you just made them not listen to you, see also
julia-language and mpv:
https://github.com/search?q=%22-Wno-unused-result%22=code

And certainly, not them, because of the bug-risk I typed above, which is really
unfortunate for such a big and widely-used project as systemd.
Also, making them switch to clang (or drop gcc support) would be really bad,
because nothing hurts FOSS and frustrates me in a project more than a
permissive license. Eww..

Sorry, if I was a little bit harsh there, I really appreciate your contribution
to FOSS and Linux development, and I would never switch to clang.
Just, please note, that, again, I'm begging you to just implement a non-default
switch that would make everyone's lives easier.

Why "everyone's"? You see,

If a new programmer encounters this "problem", they would think it's just a
"gcc bug", because "clang works as expected" (and also the mentioned projects
wrote like this in a comment), so they just disable the warnings altogether.
Nobody won, especially the programmer.
Now consider the situation where you implemented the switch, but wrote, for
example, in the manpage just that "It's not recommended". Now they will be
curious why, so they will try to find an answer, and the search will probably
lead them to the gnu.org page which has the answer.

See, how even though you might think you gave the ability to write a bad code,
in reality you would give the exact point why not to use (void)? (Which they
really need because other compilers/linters are trying to convince them
otherwise.)
Come on, at least please admit that the situation described above would still
be better than today's.

If you will find at least some of my points somewhat reasonable, please share
my comment with the people that can help bring this improvement to life.