public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/5089: -Wold-style-cast warns about cast to void
@ 2001-12-29  7:06 Nathan Sidwell
  0 siblings, 0 replies; 8+ messages in thread
From: Nathan Sidwell @ 2001-12-29  7:06 UTC (permalink / raw)
  To: nathan; +Cc: gcc-prs

The following reply was made to PR c++/5089; it has been noted by GNATS.

From: Nathan Sidwell <nathan@codesourcery.com>
To: jturner <jturner@mail.alum.rpi.edu>
Cc: gcc-prs <gcc-prs@gcc.gnu.org>, llib <llib@computer.org>,
   nathan <nathan@gcc.gnu.org>, gcc-bugs <gcc-bugs@gcc.gnu.org>,
   nobody <nobody@gcc.gnu.org>, gcc-gnats <gcc-gnats@gcc.gnu.org>
Subject: Re: c++/5089: -Wold-style-cast warns about cast to void
Date: Sat, 29 Dec 2001 15:04:14 +0000

 Jeffrey Turner wrote:
 > 
 > I don't see this as a problem.  It is what the warning says.
 > You should use the ever dangerous <reinterpret_cast> instead.
 
 	reinterpret_cast<void>(whatever)
 is invalid.
 
 nathan
 -- 
 Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
          'But that's a lie.' - 'Yes it is. What's your point?'
 nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: c++/5089: -Wold-style-cast warns about cast to void
@ 2002-01-02 10:56 Jeffrey Turner
  0 siblings, 0 replies; 8+ messages in thread
From: Jeffrey Turner @ 2002-01-02 10:56 UTC (permalink / raw)
  To: nathan; +Cc: gcc-prs

The following reply was made to PR c++/5089; it has been noted by GNATS.

From: "Jeffrey Turner" <jturner@mail.alum.rpi.edu>
To: <gcc-bugs@gcc.gnu.org>,
    <gcc-prs@gcc.gnu.org>,
    <llib@computer.org>,
    <nathan@gcc.gnu.org>,
    mputer.org@LOCALHOST,
    <nathan@gcc.gnu.org>
Cc:  
Subject: Re: c++/5089: -Wold-style-cast warns about cast to void
Date: Wed,  2 Jan 2002 14:02:59 -0500

 >Synopsis: -Wold-style-cast warns about cast to void
 >
 >State-Changed-From-To: analyzed->closed
 >State-Changed-By: nathan
 >State-Changed-When: Wed Jan  2 05:59:02 2002
 >State-Changed-Why:
 >    2002-01-02  Nathan Sidwell  <nathan@codesourcery.com>
 >    
 >    	PR c++/5089
 >    	* doc/invoke.texi (-Wold-style-cast): Only warn about non-void casts.
 >    
 >    2002-01-02  Nathan Sidwell  <nathan@codesourcery.com>
 >    
 >    	PR c++/5089
 >    	* decl2.c (reparse_absdcl_as_casts): Don't warn about casts to void.
 
 I still think this is a mistake.  If I want to be warned
 about old-style casts then the compiler should _always_
 oblige.  It should be up to the programmer whether or not
 to ignore compiler warnings.  That was the premise of C.
 I still think it's valid to let the programmer decide
 rather than the stupid compiler.  How else will we catch
 all the archaic code that hopefully should be eliminated?
 
 --Jeff Turner
 
 Who put the Sam in the "'Sama Laden Ding-Dong"?
                  


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: c++/5089: -Wold-style-cast warns about cast to void
@ 2002-01-02  5:59 nathan
  0 siblings, 0 replies; 8+ messages in thread
From: nathan @ 2002-01-02  5:59 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, llib, nathan

Synopsis: -Wold-style-cast warns about cast to void

State-Changed-From-To: analyzed->closed
State-Changed-By: nathan
State-Changed-When: Wed Jan  2 05:59:02 2002
State-Changed-Why:
    2002-01-02  Nathan Sidwell  <nathan@codesourcery.com>
    
    	PR c++/5089
    	* doc/invoke.texi (-Wold-style-cast): Only warn about non-void casts.
    
    2002-01-02  Nathan Sidwell  <nathan@codesourcery.com>
    
    	PR c++/5089
    	* decl2.c (reparse_absdcl_as_casts): Don't warn about casts to void.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5089


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: c++/5089: -Wold-style-cast warns about cast to void
@ 2001-12-30  8:26 Nathan Sidwell
  0 siblings, 0 replies; 8+ messages in thread
From: Nathan Sidwell @ 2001-12-30  8:26 UTC (permalink / raw)
  To: nathan; +Cc: gcc-prs

The following reply was made to PR c++/5089; it has been noted by GNATS.

From: Nathan Sidwell <nathan@codesourcery.com>
To: jturner <jturner@mail.alum.rpi.edu>
Cc: nathan <nathan@gcc.gnu.org>, gcc-gnats <gcc-gnats@gcc.gnu.org>,
   gcc <gcc@gcc.gnu.org>, law <law@gcc.gnu.org>,
   dosreis <dosreis@cmla.ens-cachien.fr>
Subject: Re: c++/5089: -Wold-style-cast warns about cast to void
Date: Sun, 30 Dec 2001 16:17:33 +0000

 Jeffrey Turner wrote:
 
 > >This question came up recently on a gcc mailing list.
 > >Is there a C++ way to cast something to a void?
 You're missing the point. No one claimed that static_cast<void> (foo)
 was wrong. The problem is 
 a) the assert macro
 b) static_cast<void> (foo) is a mouthful which obscures what you're trying
 to do. thinks: why am I ignoring the result of a static_cast?, oh I
 see the target type is void.  Much more up front is to have the 'void'
 at the start of the expression. void is a singularity in the type system,
 and I beleive -Wold-style-cast should treat it as such.
 
 nathan
 
 -- 
 Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
          'But that's a lie.' - 'Yes it is. What's your point?'
 nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: c++/5089: -Wold-style-cast warns about cast to void
@ 2001-12-29  5:56 Jeffrey Turner
  0 siblings, 0 replies; 8+ messages in thread
From: Jeffrey Turner @ 2001-12-29  5:56 UTC (permalink / raw)
  To: nathan; +Cc: gcc-prs

The following reply was made to PR c++/5089; it has been noted by GNATS.

From: "Jeffrey Turner" <jturner@mail.alum.rpi.edu>
To: <gcc-prs@gcc.gnu.org>,
    <llib@computer.org>,
    <nathan@gcc.gnu.org>,
    <gcc-bugs@gcc.gnu.org>,
    <nobody@gcc.gnu.org>,
    <gcc-gnats@gcc.gnu.org>
Cc:  
Subject: Re: c++/5089: -Wold-style-cast warns about cast to void
Date: Sat, 29 Dec 2001 09:10:53 -0500

 I don't see this as a problem.  It is what the warning says.
 You should use the ever dangerous <reinterpret_cast> instead.
 
 --Jeff Turner
 
 Who put the Sam in the "'Sama Laden Ding-Dong"?
 
 
 ---------- Original Message ----------------------------------
 From: nathan@gcc.gnu.org
 Reply-To: nathan@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org,llib@computer.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org
 Date:  18 Dec 2001 22:23:40 -0000
 
 >Synopsis: -Wold-style-cast warns about cast to void
 >
 >State-Changed-From-To: open->analyzed
 >State-Changed-By: nathan
 >State-Changed-When: Tue Dec 18 14:23:40 2001
 >State-Changed-Why:
 >    I think we shouldn't warn for (void)expr, 
 >    (my own c++ code uses that, for instance)
 >
 >http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5089
 >
                  


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: c++/5089: -Wold-style-cast warns about cast to void
@ 2001-12-27 13:09 nathan
  0 siblings, 0 replies; 8+ messages in thread
From: nathan @ 2001-12-27 13:09 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, llib, nathan, nobody

Synopsis: -Wold-style-cast warns about cast to void

Responsible-Changed-From-To: unassigned->nathan
Responsible-Changed-By: nathan
Responsible-Changed-When: Thu Dec 27 13:09:14 2001
Responsible-Changed-Why:
    patch in progress

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5089


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: c++/5089: -Wold-style-cast warns about cast to void
@ 2001-12-18 14:23 nathan
  0 siblings, 0 replies; 8+ messages in thread
From: nathan @ 2001-12-18 14:23 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, llib, nobody

Synopsis: -Wold-style-cast warns about cast to void

State-Changed-From-To: open->analyzed
State-Changed-By: nathan
State-Changed-When: Tue Dec 18 14:23:40 2001
State-Changed-Why:
    I think we shouldn't warn for (void)expr, 
    (my own c++ code uses that, for instance)

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5089


^ permalink raw reply	[flat|nested] 8+ messages in thread

* c++/5089: -Wold-style-cast warns about cast to void
@ 2001-12-11 22:46 llib
  0 siblings, 0 replies; 8+ messages in thread
From: llib @ 2001-12-11 22:46 UTC (permalink / raw)
  To: gcc-gnats


>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:


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2002-01-02 18:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-29  7:06 c++/5089: -Wold-style-cast warns about cast to void Nathan Sidwell
  -- strict thread matches above, loose matches on Subject: below --
2002-01-02 10:56 Jeffrey Turner
2002-01-02  5:59 nathan
2001-12-30  8:26 Nathan Sidwell
2001-12-29  5:56 Jeffrey Turner
2001-12-27 13:09 nathan
2001-12-18 14:23 nathan
2001-12-11 22:46 llib

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).