public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/66425] (void) cast doesn't suppress __attribute__((warn_unused_result))
Date: Thu, 11 Jun 2015 06:06:00 -0000	[thread overview]
Message-ID: <bug-66425-4-WwcJucUqCO@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-66425-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Filipe Brandenburger from comment #6)
> Then please explain to me how this:
> 
>   (void) foo();
> 
> is any worse than this:
> 
>   int ignored __attribute__((unused));
>   ignored = foo();
>   /* do nothing with ignored here */
> 
> You can force me to assign the return value to something, but you can't
> really force me to do something useful with it...

I am not forcing you to do anything.  You (or others) are forcing yourself by
using this attribute.  GCC is not forcing you to use this attribute at all. 
You just don't the deinfition of the attribute which was decided on over 10
years ago.  Yes 10 years.  clang was not around back then.  So one could say
clang's attribute is not a copy of GCC's but rather a different one all
together.

> 
> In the cases above, I think the former is a much more clear way to express
> my intent to ignore that value, I'm telling the compiler "yeah, I know, I'm
> supposed to use this value, but in this particular case I really know what
> I'm doing so please bear with me here."
> 
> The -Wunused-result warnings would be a lot more useful (or, actually, just
> useful) if I was able to whitelist the places where I want to ignore the
> values, since right now my only practical choice is to disable it completely
> with -Wno-unused-result.
> 
> This is an example of a *real* problem that would have been caught by this
> warning:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509#c28

Except that assert definition is broken, the standard assert macro in C/C++
does not have any side effects for NDEBUG.  And actually that does not show a
real problem with the attribute but rather they have asserts which have side
effects so they worked out that problem by defining their own assert :).  Still
not a GCC bug :).

> 
> And it's not just LLVM... Other linters and static analysis tools seem to
> agree that a (void) cast is an explicit indication that the coder meant to
> ignore those results, so why would gcc want to be the one exception here?

Again this has nothing to do with other lints, this attribute was designed so
you can't ignore the return value.  And most lints/static analysis tools will
also look to see if you not really ignoring the return value in that you use it
in an error case fashion.  casting to void does not always cause (and really
should not cause) static analysis to ignore what you did was broken for the
API.  It is not GCC's fault people are starting to misuse this attribute; you
should write into those projects instead saying they are misunderstanding the
attribute is being used incorrectly.  I bet some of them, really don't want a
warning even with a cast to void.

> 
> Thanks!
> Filipe


  parent reply	other threads:[~2015-06-11  6:06 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-05  0:38 [Bug c/66425] New: " rusty at rustcorp dot com.au
2015-06-05  7:21 ` [Bug c/66425] " manu at gcc dot gnu.org
2015-06-11  0:51 ` filbranden at google dot com
2015-06-11  5:39 ` pinskia at gcc dot gnu.org
2015-06-11  5:52 ` koct9i at gmail dot com
2015-06-11  5:55 ` filbranden at google dot com
2015-06-11  6:06 ` pinskia at gcc dot gnu.org [this message]
2015-06-11  6:37 ` filbranden at google dot com
2015-06-11  6:46 ` filbranden at google dot com
2015-06-11  6:49 ` lucas.de.marchi at gmail dot com
2015-06-11  8:41 ` manu at gcc dot gnu.org
2015-06-11 14:10 ` schwab@linux-m68k.org
2015-06-11 14:25 ` manu at gcc dot gnu.org
2015-06-11 15:08 ` lucas.de.marchi at gmail dot com
2015-06-11 15:49 ` joseph at codesourcery dot com
2015-06-11 16:57 ` filbranden at google dot com
2015-06-14 17:29 ` segher at gcc dot gnu.org
2015-08-20  5:35 ` rusty at rustcorp dot com.au
2015-08-20  6:05 ` filbranden at google dot com
2020-03-28 11:07 ` pskocik at gmail dot com
2021-07-27 19:33 ` ndesaulniers at google dot com
2023-04-22 21:20 ` achurch+gcc at achurch dot org
2023-04-23  7:07 ` sjames at gcc dot gnu.org
2023-04-23  7:53 ` achurch+gcc at achurch dot org
2023-04-23 20:00 ` segher at gcc dot gnu.org
2023-04-23 21:51 ` achurch+gcc at achurch dot org
2023-04-23 22:03 ` pinskia at gcc dot gnu.org
2023-04-23 23:06 ` achurch+gcc at achurch dot org
2023-04-24  6:45 ` rusty at rustcorp dot com.au
2023-04-24  8:21 ` achurch+gcc at achurch dot org
2023-04-24  8:26 ` jakub at gcc dot gnu.org
2023-04-24  8:35 ` fw at gcc dot gnu.org
2023-04-24  9:06 ` segher at gcc dot gnu.org
2023-04-24  9:18 ` jengelh at inai dot de
2023-04-24  9:41 ` achurch+gcc at achurch dot org
2023-08-09 22:33 ` romato.san1337 at gmail dot com
2023-08-09 23:09 ` ed at catmur dot uk
2023-08-10  9:23 ` muecker at gwdg dot de
2023-08-10 12:25 ` romato.san1337 at gmail dot com
2023-08-10 18:12 ` ed at catmur dot uk
2023-08-17 13:09 ` romato.san1337 at gmail dot com
2023-09-06 11:07 ` segher at gcc dot gnu.org
2023-09-06 11:51 ` achurch+gcc at achurch dot org
2024-02-14 11:32 ` groessler_christian at yahoo dot de

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-66425-4-WwcJucUqCO@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).