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

[EMAIL PROTECTED]:~/C++/src> ~/gnu/20050311/results/bin/g++ -c sc.cc

I added more flags

[EMAIL PROTECTED]:~/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'
[EMAIL PROTECTED]:~/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

Reply via email to