public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/20475] New: static_cast falsely allows const to be cast away
@ 2005-03-14 19:02 dcb314 at hotmail dot com
  2005-03-14 20:13 ` [Bug c++/20475] " pinskia at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 14+ messages in thread
From: dcb314 at hotmail dot com @ 2005-03-14 19:02 UTC (permalink / raw)
  To: gcc-bugs

I just tried the following block of C++ code with g++ 20050311, the
latest snapshot.

void f()
{
        char * pj2 = static_cast < char * > ("fred");
}

The compiler said

dcb@linux:~/C++/src> ~/gnu/20050311/results/bin/g++ -c sc.cc

I added more flags

dcb@linux:~/C++/src> ~/gnu/20050311/results/bin/g++ -g -O2 -Wall -ansi -pedantic
-c sc.cc
sc.cc: In function `void f()':
sc.cc:5: warning: unused variable 'pj2'
dcb@linux:~/C++/src>

However, my reading of Stroustrup 3, page 414, section 15.4.2.1 says that
static_cast can't be used to cast away const.

I think the compiler should complain about the above code. Here is Intel C++ 8.1
doing what I want.

sc.cc(5): error: static_cast cannot cast away const or other type qualifiers
        char * pj2 = static_cast < char * > ("fred");
                     ^

This example derived from real code in Suse Linux 9.2

-- 
           Summary: static_cast falsely allows const to be cast away
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dcb314 at hotmail dot com
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-pc-linux-gnu


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


^ permalink raw reply	[flat|nested] 14+ messages in thread
[parent not found: <bug-20475-9596@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2008-08-06 18:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-14 19:02 [Bug c++/20475] New: static_cast falsely allows const to be cast away dcb314 at hotmail dot com
2005-03-14 20:13 ` [Bug c++/20475] " pinskia at gcc dot gnu dot org
2005-03-14 20:14 ` pinskia at gcc dot gnu dot org
2005-05-15 14:37 ` lerdsuwa at gcc dot gnu dot org
2005-05-15 22:45 ` schlie at comcast dot net
2005-05-15 22:50 ` schlie at comcast dot net
2005-05-16  0:15 ` gdr at integrable-solutions dot net
2005-05-16  2:44 ` schlie at comcast dot net
2005-05-16  2:54 ` gdr at integrable-solutions dot net
2005-05-16  5:08 ` schlie at comcast dot net
2005-05-16  9:07 ` gdr at integrable-solutions dot net
2005-05-16 13:26 ` schlie at comcast dot net
2005-05-16 17:00 ` gdr at integrable-solutions dot net
     [not found] <bug-20475-9596@http.gcc.gnu.org/bugzilla/>
2008-08-06 18:43 ` 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).