public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35711]  New: bad text in -Wcast-qual warning (forgets volatile)
@ 2008-03-26 20:14 sebor at roguewave dot com
  2008-03-27 14:15 ` [Bug c++/35711] " manu at gcc dot gnu dot org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: sebor at roguewave dot com @ 2008-03-26 20:14 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 837 bytes --]

The text of the warning below is incorrect and misleading -- the cast
actually casts away the volatile qualifier, not constness. The warning
is misleading when the type of the source is both const and volatile
qualified.

$ cat t.cpp && g++ -c -Wcast-qual t.cpp
int* foo (volatile int *p)
{
    return (int*)p;
}
t.cpp: In function ‘int* foo(volatile int*)’:
t.cpp:3: warning: cast from type ‘volatile int*’ to type ‘int*’ casts away
constness


-- 
           Summary: bad text in -Wcast-qual warning (forgets volatile)
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sebor at roguewave dot com


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


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

* [Bug c++/35711] bad text in -Wcast-qual warning (forgets volatile)
  2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
@ 2008-03-27 14:15 ` manu at gcc dot gnu dot org
  2008-08-29  1:58 ` manu at gcc dot gnu dot org
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-03-27 14:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from manu at gcc dot gnu dot org  2008-03-27 14:14 -------
Confirmed in trunk and GCC 4.3.0


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |diagnostic
      Known to fail|                            |4.3.0
   Last reconfirmed|0000-00-00 00:00:00         |2008-03-27 14:14:41
               date|                            |


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


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

* [Bug c++/35711] bad text in -Wcast-qual warning (forgets volatile)
  2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
  2008-03-27 14:15 ` [Bug c++/35711] " manu at gcc dot gnu dot org
@ 2008-08-29  1:58 ` manu at gcc dot gnu dot org
  2008-08-29  3:10 ` pinskia at gcc dot gnu dot org
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-29  1:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from manu at gcc dot gnu dot org  2008-08-29 01:56 -------
The obvious fix is to say "qualifiers" instead of constness. At the point of
warning we only know that the conversion is invalid but not why. It is almost
magic that we only warn for qualifiers.


-- 


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


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

* [Bug c++/35711] bad text in -Wcast-qual warning (forgets volatile)
  2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
  2008-03-27 14:15 ` [Bug c++/35711] " manu at gcc dot gnu dot org
  2008-08-29  1:58 ` manu at gcc dot gnu dot org
@ 2008-08-29  3:10 ` pinskia at gcc dot gnu dot org
  2008-08-29  3:32 ` manu at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-08-29  3:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2008-08-29 03:08 -------
(In reply to comment #2)
>  It is almost  magic that we only warn for qualifiers.

You can get the same message with an error message too:
int* foo (volatile int *p)
{
    return static_cast<int*>p;
}

As static_cast cannot cast away qualifiers.  Also note we (Sony) changed our
GCC to just say qualifiers instead of constness.


-- 


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


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

* [Bug c++/35711] bad text in -Wcast-qual warning (forgets volatile)
  2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
                   ` (2 preceding siblings ...)
  2008-08-29  3:10 ` pinskia at gcc dot gnu dot org
@ 2008-08-29  3:32 ` manu at gcc dot gnu dot org
  2008-08-29  3:35 ` pinskia at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-29  3:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from manu at gcc dot gnu dot org  2008-08-29 03:31 -------
(In reply to comment #3)
> (In reply to comment #2)
> >  It is almost  magic that we only warn for qualifiers.
>
> You can get the same message with an error message too:

Sorry, I meant that it is almost magic that we only given an error/warning when
casting away qualifiers and not for other invalid conversions since the only
thing that we really know at the point of giving the warning/error is that a
conversion was reject.

> As static_cast cannot cast away qualifiers.  Also note we (Sony) changed our
> GCC to just say qualifiers instead of constness.

Why such changes are not contributed back to FSF's GCC? I thought you would
know better... :-(


-- 


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


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

* [Bug c++/35711] bad text in -Wcast-qual warning (forgets volatile)
  2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
                   ` (3 preceding siblings ...)
  2008-08-29  3:32 ` manu at gcc dot gnu dot org
@ 2008-08-29  3:35 ` pinskia at gcc dot gnu dot org
  2008-08-29  3:38 ` manu at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-08-29  3:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2008-08-29 03:33 -------
(In reply to comment #4)
> Why such changes are not contributed back to FSF's GCC? I thought you would
> know better... :-(

It only happened in the last two months, it is on my list of things to
contribute back in the near future.


-- 


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


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

* [Bug c++/35711] bad text in -Wcast-qual warning (forgets volatile)
  2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
                   ` (4 preceding siblings ...)
  2008-08-29  3:35 ` pinskia at gcc dot gnu dot org
@ 2008-08-29  3:38 ` manu at gcc dot gnu dot org
  2009-01-07  2:41 ` ian at airs dot com
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-29  3:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from manu at gcc dot gnu dot org  2008-08-29 03:37 -------
OK. Anyway, I am testing a patch for this already.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |manu at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2008-03-27 14:14:41         |2008-08-29 03:37:35
               date|                            |


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


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

* [Bug c++/35711] bad text in -Wcast-qual warning (forgets volatile)
  2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
                   ` (5 preceding siblings ...)
  2008-08-29  3:38 ` manu at gcc dot gnu dot org
@ 2009-01-07  2:41 ` ian at airs dot com
  2009-01-07  9:39 ` schwab at suse dot de
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ian at airs dot com @ 2009-01-07  2:41 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 725 bytes --]



------- Comment #7 from ian at airs dot com  2009-01-07 02:41 -------
Probably related to this, we get a bad warning for

extern void** foo();
const void** bar() { return (const void **) foo(); }

foo.cc:2: warning: cast from type ‘void**’ to type ‘const void**’ casts away
constness

I don't see any way that this cast can be described as casting away constness. 
I don't see why we should warn about adding a const qualifier.


-- 

ian at airs dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ian at airs dot com


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


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

* [Bug c++/35711] bad text in -Wcast-qual warning (forgets volatile)
  2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
                   ` (6 preceding siblings ...)
  2009-01-07  2:41 ` ian at airs dot com
@ 2009-01-07  9:39 ` schwab at suse dot de
  2009-01-07 14:27 ` ian at airs dot com
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: schwab at suse dot de @ 2009-01-07  9:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from schwab at suse dot de  2009-01-07 09:39 -------
Casting (void **) to (const void **) is unsafe so it is not ok to drop the
warning.


-- 


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


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

* [Bug c++/35711] bad text in -Wcast-qual warning (forgets volatile)
  2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
                   ` (7 preceding siblings ...)
  2009-01-07  9:39 ` schwab at suse dot de
@ 2009-01-07 14:27 ` ian at airs dot com
  2009-01-07 15:35 ` joseph at codesourcery dot com
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ian at airs dot com @ 2009-01-07 14:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from ian at airs dot com  2009-01-07 14:27 -------
How is it unsafe?  All the const qualifier on a pointer means is that the
memory will not be changed through that pointer.


-- 


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


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

* [Bug c++/35711] bad text in -Wcast-qual warning (forgets volatile)
  2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
                   ` (8 preceding siblings ...)
  2009-01-07 14:27 ` ian at airs dot com
@ 2009-01-07 15:35 ` joseph at codesourcery dot com
  2009-01-07 15:42 ` ian at airs dot com
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: joseph at codesourcery dot com @ 2009-01-07 15:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from joseph at codesourcery dot com  2009-01-07 15:34 -------
Subject: Re:  bad text in -Wcast-qual warning (forgets volatile)

On Wed, 7 Jan 2009, ian at airs dot com wrote:

> How is it unsafe?  All the const qualifier on a pointer means is that the
> memory will not be changed through that pointer.

http://c-faq.com/ansi/constmismatch.html

gives the standard example for why such conversions are unsafe.


-- 


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


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

* [Bug c++/35711] bad text in -Wcast-qual warning (forgets volatile)
  2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
                   ` (9 preceding siblings ...)
  2009-01-07 15:35 ` joseph at codesourcery dot com
@ 2009-01-07 15:42 ` ian at airs dot com
  2009-02-08 15:52 ` manu at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ian at airs dot com @ 2009-01-07 15:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from ian at airs dot com  2009-01-07 15:41 -------
Oh yeah, sorry for the noise.

In any case, the warning message is wrong, as the cast does not "cast away
constness".


-- 


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


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

* [Bug c++/35711] bad text in -Wcast-qual warning (forgets volatile)
  2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
                   ` (10 preceding siblings ...)
  2009-01-07 15:42 ` ian at airs dot com
@ 2009-02-08 15:52 ` manu at gcc dot gnu dot org
  2009-04-21 19:49 ` manu at gcc dot gnu dot org
  2009-04-21 19:53 ` manu at gcc dot gnu dot org
  13 siblings, 0 replies; 15+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-02-08 15:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from manu at gcc dot gnu dot org  2009-02-08 15:51 -------
Patch: http://gcc.gnu.org/ml/gcc-patches/2008-10/msg00806.html


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|manu at gcc dot gnu dot org |unassigned at gcc dot gnu
                   |                            |dot org
                URL|                            |http://gcc.gnu.org/ml/gcc-
                   |                            |patches/2008-
                   |                            |10/msg00806.html
             Status|ASSIGNED                    |NEW
           Keywords|                            |patch


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


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

* [Bug c++/35711] bad text in -Wcast-qual warning (forgets volatile)
  2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
                   ` (11 preceding siblings ...)
  2009-02-08 15:52 ` manu at gcc dot gnu dot org
@ 2009-04-21 19:49 ` manu at gcc dot gnu dot org
  2009-04-21 19:53 ` manu at gcc dot gnu dot org
  13 siblings, 0 replies; 15+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-04-21 19:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #13 from manu at gcc dot gnu dot org  2009-04-21 19:49 -------
Subject: Bug 35711

Author: manu
Date: Tue Apr 21 19:49:23 2009
New Revision: 146537

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146537
Log:
2009-04-21  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

        PR c++/35711
cp/
        * typeck.c (check_for_casting_away_constness): We diagnose casting
        away any qualifiers not just constness.
        (casts_away_constness): Mention that it handles more than just
        constness.
testsuite/
        * g++.dg/warn/pr35711.C: New.
        * g++.dg/conversion/ptrmem2.C: Update.

Added:
    trunk/gcc/testsuite/g++.dg/warn/pr35711.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/conversion/ptrmem2.C


-- 


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


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

* [Bug c++/35711] bad text in -Wcast-qual warning (forgets volatile)
  2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
                   ` (12 preceding siblings ...)
  2009-04-21 19:49 ` manu at gcc dot gnu dot org
@ 2009-04-21 19:53 ` manu at gcc dot gnu dot org
  13 siblings, 0 replies; 15+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-04-21 19:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #14 from manu at gcc dot gnu dot org  2009-04-21 19:53 -------
I am going to mark this as FIXED for GCC 4.5.

A possible enhancement could be to mention which qualifiers are casted away.
However, this is not trivial and the warning already mentions the types, so
perhaps it is unnecessary.


-- 

manu at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2009-04-21 19:53 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-26 20:14 [Bug c++/35711] New: bad text in -Wcast-qual warning (forgets volatile) sebor at roguewave dot com
2008-03-27 14:15 ` [Bug c++/35711] " manu at gcc dot gnu dot org
2008-08-29  1:58 ` manu at gcc dot gnu dot org
2008-08-29  3:10 ` pinskia at gcc dot gnu dot org
2008-08-29  3:32 ` manu at gcc dot gnu dot org
2008-08-29  3:35 ` pinskia at gcc dot gnu dot org
2008-08-29  3:38 ` manu at gcc dot gnu dot org
2009-01-07  2:41 ` ian at airs dot com
2009-01-07  9:39 ` schwab at suse dot de
2009-01-07 14:27 ` ian at airs dot com
2009-01-07 15:35 ` joseph at codesourcery dot com
2009-01-07 15:42 ` ian at airs dot com
2009-02-08 15:52 ` manu at gcc dot gnu dot org
2009-04-21 19:49 ` manu at gcc dot gnu dot org
2009-04-21 19:53 ` manu 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).