From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 79C5B385842A; Mon, 24 Apr 2023 09:06:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79C5B385842A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682327167; bh=7mpbQW8Nv2iLf0NDJ1tL1R6KsEaqd2tu68uY0G6Hn3Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NvWkJAZBbuYEF04i3PyZPRJmT0dZCyTvP0Ntijkw9f06HtwZSrrUX72iDMScphNnY pvf9NOPB7fYu9PUZ/flj1aDhkN+RH4PqbiDdrv8tl7Lu7J6XxHMFKJ4ZbmBE7I+qwn X34fxibyU8ayluClqg4f5dkOBK+e/p3woDfP4ysk= From: "segher at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/66425] (void) cast doesn't suppress __attribute__((warn_unused_result)) Date: Mon, 24 Apr 2023 09:06:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.9.2 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: segher at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D66425 --- Comment #51 from Segher Boessenkool --- (In reply to rusty from comment #47) > Civility please. Thank you. > As Andrew Pinski says "people are mis-using this attribute", and Jakub > Jelinek makes a similar point. The use of _wur has changed from "ignoring > the result is criminally wrong" to "possibly wrong". And that is the core of why this issue reinflames once in a while: some peo= ple abuse the attribute, and the compiler cannot read minds. The documentation of this attribute states 'warn_unused_result' The 'warn_unused_result' attribute causes a warning to be emitted if a caller of the function with this attribute does not use its return value. This is useful for functions where not checking the result is either a security problem or always a bug, such as 'realloc'. The "non-bugs" section of the manual ("Certain Changes We Don't Want to Mak= e" says * Warning when a non-void function value is ignored. C contains many standard functions that return a value that most programs choose to ignore. One obvious example is 'printf'. Warning about this practice only leads the defensive programmer to clutter programs with dozens of casts to 'void'. Such casts are required so frequently that they become visual noise. Writing those casts becomes so automatic that they no longer convey useful information about the intentions of the programmer. For functions where the return value should never be ignored, use the 'warn_unused_result' function attribute (*note Function Attributes::). Completely useless casts to void cluttered programs decades ago already, we do not fear cargo cult, instead we observed it already existed. And finally there is '-Wno-unused-result' Do not warn if a caller of a function marked with attribute 'warn_unused_result' (*note Function Attributes::) does not use its return value. The default is '-Wunused-result'. A caller that casts a return value to void *explicitly* does not use that return value. > I still put a comment complaining about this every time I hit it, which is > about once or twice a year. But I have little more to say; it's been alm= ost > 20 year after all :) Changing the behaviour of this attribute after all that time will not make things better. But perhaps we can say a bit more in the documentation, maybe at one of the three very concise quotes above? Say half a line worth= ?=