From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32178 invoked by alias); 12 Dec 2001 06:46:04 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 32129 invoked by uid 71); 12 Dec 2001 06:46:02 -0000 Resent-Date: 12 Dec 2001 06:46:02 -0000 Resent-Message-ID: <20011212064602.32128.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, llib@computer.org Received:(qmail 30866 invoked by uid 61); 12 Dec 2001 06:42:23 -0000 Message-Id:<20011212064223.30865.qmail@sources.redhat.com> Date: Tue, 11 Dec 2001 22:46:00 -0000 From: llib@computer.org Reply-To: llib@computer.org To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version:gnatsweb-2.9.2 (1.1.1.1.2.21) Subject: c++/5089: -Wold-style-cast warns about cast to void X-SW-Source: 2001-12/txt/msg00706.txt.bz2 List-Id: >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 header, which simply includes ) 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(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 // 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: