public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/24667]  New: -Wcast-qual fails to reject offending cast
@ 2005-11-04  6:11 fang at csl dot cornell dot edu
  2005-11-04  7:47 ` [Bug c++/24667] " fang at csl dot cornell dot edu
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: fang at csl dot cornell dot edu @ 2005-11-04  6:11 UTC (permalink / raw)
  To: gcc-bugs

g++ -Wcast-qual doesn't seem to reject the following code, it just accepts
quitely without warning.  

//======= "foo.cc" ==================
int main(int, char**) {
const int foo[2] = {1,1};
((int*)foo)[0] = 0;
}
//=========================

command: g++ -Wcast-qual foo.cc

program output: (none)

expected output (from g++ 3.3):
foo.cc: In function `int main(int, char**)':
foo.cc:3: warning: cast from `const int*' to `int*' discards qualifiers from 
   pointer target type

keywords: accepts-invalid

known to work: 3.3.x
known to fail: 4.0.2

remarks: possibly closely related to PR 20475

Originator: Dmitry Markman <dmarkman at mac dot com>, reported on
xcode-users@lists.apple.com.
(I wasn't able to add him to the CC list.)


-- 
           Summary: -Wcast-qual fails to reject offending cast
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fang at csl dot cornell dot edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24667


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

* [Bug c++/24667] -Wcast-qual fails to reject offending cast
  2005-11-04  6:11 [Bug c++/24667] New: -Wcast-qual fails to reject offending cast fang at csl dot cornell dot edu
@ 2005-11-04  7:47 ` fang at csl dot cornell dot edu
  2005-11-04 14:33 ` [Bug c++/24667] [4.0/4.1 Regression] -Wcast-qual fails to reject offending cast for a old style cast pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: fang at csl dot cornell dot edu @ 2005-11-04  7:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from fang at csl dot cornell dot edu  2005-11-04 07:47 -------
also known to work: 3.4.0


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24667


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

* [Bug c++/24667] [4.0/4.1 Regression] -Wcast-qual fails to reject offending cast for a old style cast
  2005-11-04  6:11 [Bug c++/24667] New: -Wcast-qual fails to reject offending cast fang at csl dot cornell dot edu
  2005-11-04  7:47 ` [Bug c++/24667] " fang at csl dot cornell dot edu
@ 2005-11-04 14:33 ` pinskia at gcc dot gnu dot org
  2005-11-04 17:56 ` fang at csl dot cornell dot edu
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-11-04 14:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2005-11-04 14:33 -------
Hmm, old (C) style casts are weird, IIRC they act as either a static_cast, a
reinterpret_cast, or a const_cast.  In this case they are acting like a
const_cast which is what is normally goes and gets rid of a qualifier.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor
            Summary|-Wcast-qual fails to reject |[4.0/4.1 Regression] -Wcast-
                   |offending cast              |qual fails to reject
                   |                            |offending cast for a old
                   |                            |style cast
   Target Milestone|---                         |4.0.3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24667


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

* [Bug c++/24667] [4.0/4.1 Regression] -Wcast-qual fails to reject offending cast for a old style cast
  2005-11-04  6:11 [Bug c++/24667] New: -Wcast-qual fails to reject offending cast fang at csl dot cornell dot edu
  2005-11-04  7:47 ` [Bug c++/24667] " fang at csl dot cornell dot edu
  2005-11-04 14:33 ` [Bug c++/24667] [4.0/4.1 Regression] -Wcast-qual fails to reject offending cast for a old style cast pinskia at gcc dot gnu dot org
@ 2005-11-04 17:56 ` fang at csl dot cornell dot edu
  2005-11-04 21:18 ` janis at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: fang at csl dot cornell dot edu @ 2005-11-04 17:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from fang at csl dot cornell dot edu  2005-11-04 17:56 -------
Am I correct in expecting that const_cast<...> should pass -Wcast-qual without
warning?  That's the way I use it (in the few and rare cases that demand it)
and it's met my expectations thus far.  I'm kind of surprised I haven't tripped
this bug myself, but that's because I stopped using C-style casts long ago,
enforced by -Wold-style-cast -Werror.  Adding -Wold-style-cast does trip a
warning about old casts with the posted code, but nothing further about
discarding qualifiers (gcc4).  


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24667


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

* [Bug c++/24667] [4.0/4.1 Regression] -Wcast-qual fails to reject offending cast for a old style cast
  2005-11-04  6:11 [Bug c++/24667] New: -Wcast-qual fails to reject offending cast fang at csl dot cornell dot edu
                   ` (2 preceding siblings ...)
  2005-11-04 17:56 ` fang at csl dot cornell dot edu
@ 2005-11-04 21:18 ` janis at gcc dot gnu dot org
  2005-11-15 17:50 ` [Bug c++/24667] [4.0/4.1 Regression] -Wcast-qual fails to warn about " mmitchel at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: janis at gcc dot gnu dot org @ 2005-11-04 21:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from janis at gcc dot gnu dot org  2005-11-04 21:18 -------
A regression test identified the following patch to change handling of
C-style casts for PR c++/14035:

http://gcc.gnu.org/viewcvs?view=rev&rev=89300

r89300 | mmitchel | 2004-10-19 23:24:20 +0000 (Tue, 19 Oct 2004) | 35 lines


-- 

janis at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mmitchel at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24667


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

* [Bug c++/24667] [4.0/4.1 Regression] -Wcast-qual fails to warn about offending cast for a old style cast
  2005-11-04  6:11 [Bug c++/24667] New: -Wcast-qual fails to reject offending cast fang at csl dot cornell dot edu
                   ` (3 preceding siblings ...)
  2005-11-04 21:18 ` janis at gcc dot gnu dot org
@ 2005-11-15 17:50 ` mmitchel at gcc dot gnu dot org
  2005-11-15 17:52 ` mmitchel at gcc dot gnu dot org
  2005-11-15 17:57 ` mmitchel at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-11-15 17:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from mmitchel at gcc dot gnu dot org  2005-11-15 17:50 -------
Subject: Bug 24667

Author: mmitchel
Date: Tue Nov 15 17:50:43 2005
New Revision: 107031

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107031
Log:
        PR c++/24667
        * typeck.c (check_for_casting_away_constness): Use the diag_fn.
        (build_const_cast_1): Call it, for C-style casts.
        PR c++/24667
        * g++.dg/warn/Wcast-qual1.C: New test.

Added:
    branches/gcc-4_0-branch/gcc/testsuite/g++.dg/warn/Wcast-qual1.C
Modified:
    branches/gcc-4_0-branch/gcc/cp/ChangeLog
    branches/gcc-4_0-branch/gcc/cp/typeck.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24667


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

* [Bug c++/24667] [4.0/4.1 Regression] -Wcast-qual fails to warn about offending cast for a old style cast
  2005-11-04  6:11 [Bug c++/24667] New: -Wcast-qual fails to reject offending cast fang at csl dot cornell dot edu
                   ` (4 preceding siblings ...)
  2005-11-15 17:50 ` [Bug c++/24667] [4.0/4.1 Regression] -Wcast-qual fails to warn about " mmitchel at gcc dot gnu dot org
@ 2005-11-15 17:52 ` mmitchel at gcc dot gnu dot org
  2005-11-15 17:57 ` mmitchel at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-11-15 17:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from mmitchel at gcc dot gnu dot org  2005-11-15 17:52 -------
Subject: Bug 24667

Author: mmitchel
Date: Tue Nov 15 17:52:34 2005
New Revision: 107032

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107032
Log:
        PR c++/24667
        * typeck.c (check_for_casting_away_constness): Use the diag_fn.
        (build_const_cast_1): Call it, for C-style casts.
        PR c++/24667
        * g++.dg/warn/Wcast-qual1.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/warn/Wcast-qual1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24667


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

* [Bug c++/24667] [4.0/4.1 Regression] -Wcast-qual fails to warn about offending cast for a old style cast
  2005-11-04  6:11 [Bug c++/24667] New: -Wcast-qual fails to reject offending cast fang at csl dot cornell dot edu
                   ` (5 preceding siblings ...)
  2005-11-15 17:52 ` mmitchel at gcc dot gnu dot org
@ 2005-11-15 17:57 ` mmitchel at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-11-15 17:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from mmitchel at gcc dot gnu dot org  2005-11-15 17:57 -------
Fixed in 4.0.3.


-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24667


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

end of thread, other threads:[~2005-11-15 17:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-04  6:11 [Bug c++/24667] New: -Wcast-qual fails to reject offending cast fang at csl dot cornell dot edu
2005-11-04  7:47 ` [Bug c++/24667] " fang at csl dot cornell dot edu
2005-11-04 14:33 ` [Bug c++/24667] [4.0/4.1 Regression] -Wcast-qual fails to reject offending cast for a old style cast pinskia at gcc dot gnu dot org
2005-11-04 17:56 ` fang at csl dot cornell dot edu
2005-11-04 21:18 ` janis at gcc dot gnu dot org
2005-11-15 17:50 ` [Bug c++/24667] [4.0/4.1 Regression] -Wcast-qual fails to warn about " mmitchel at gcc dot gnu dot org
2005-11-15 17:52 ` mmitchel at gcc dot gnu dot org
2005-11-15 17:57 ` mmitchel at gcc dot gnu dot org

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