public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: llib@computer.org To: gcc-gnats@gcc.gnu.org Subject: c++/5089: -Wold-style-cast warns about cast to void Date: Tue, 11 Dec 2001 22:46:00 -0000 [thread overview] Message-ID: <20011212064223.30865.qmail@sources.redhat.com> (raw) >Number: 5089 >Category: c++ >Synopsis: -Wold-style-cast warns about cast to void >Confidential: no >Severity: non-critical >Priority: low >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Tue Dec 11 22:46:02 PST 2001 >Closed-Date: >Last-Modified: >Originator: Bill Clarke >Release: 3.0.2 >Organization: >Environment: sparc-sun-solaris2.8 >Description: why is this a problem? "assert(EX)" (at least on my system) expands to "(void)((EX) || (__assert(#EX, __FILE__, __LINE__), 0))" which means use of assert (even via the new <cassert> header, which simply includes <assert.h>) will give a warning. casting to void is thought (by some) to be good practice for ignoring a return value from an expression. perhaps c++ code should instead do a static_cast<void>(expr)! (this is excessive) void initialisation also works: void(expr). one could claim that this warning is only for occasional testing, and not for everyday use in which case this problem should be mentioned in the documentation for -Wold-style-cast. >How-To-Repeat: problem is obvious. solution is not. >Fix: either: - change -Wold-style-cast to not warn about cast to void (and add another warning -Wold-style-void-cast?) - change <cassert>/<bits/std_cassert.h>/<assert.h> by header munging to do a void initialisation: here is a diff with our system assert.h:[ --- /usr/include/assert.h Thu Jan 6 09:09:40 2000 +++ assert.h Wed Dec 12 17:24:18 2001 @@ -41,7 +41,9 @@ #else -#if defined(__STDC__) +#ifdef __cplusplus +#define assert(EX) (void((EX) || (__assert(#EX, __FILE__, __LINE__), 0))) +#elif defined(__STDC__) #define assert(EX) (void)((EX) || (__assert(#EX, __FILE__, __LINE__), 0)) #else #define assert(EX) (void)((EX) || (_assert("EX", __FILE__, __LINE__), 0)) ]end of diff. normal user code (or other system header macros) that do casts to void will still get lots of warnings however. >Release-Note: >Audit-Trail: >Unformatted:
next reply other threads:[~2001-12-12 6:46 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2001-12-11 22:46 llib [this message] 2001-12-18 14:23 nathan 2001-12-27 13:09 nathan 2001-12-29 5:56 Jeffrey Turner 2001-12-29 7:06 Nathan Sidwell 2001-12-30 8:26 Nathan Sidwell 2002-01-02 5:59 nathan 2002-01-02 10:56 Jeffrey Turner
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=20011212064223.30865.qmail@sources.redhat.com \ --to=llib@computer.org \ --cc=gcc-gnats@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: linkBe 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).