14211 – [3.3/3.4/4.0 Regression] const_cast returns lvalue but should be rvalue (original) (raw)

Description d.binderman 2004-02-19 15:06:30 UTC

// Given the following C++ code

void f( char * str) {

char * & m = const_cast<char *>( str);

}

/* then g++ 332 says not a lot.

[dcb@localhost src]$ ~/gnu/gcc332/results/bin/g++ -c -g -O2 -Wall -ansi -pedantic cc.cc cc.cc: In function void f(char*)': cc.cc:7: warning: unused variable char*&m' [dcb@localhost src]$

But Intel C++ 8.0 says

[dcb@localhost src]$ icc cc.cc cc.cc(7): error: initial value of reference to non-const must be an lvalue char * & m = const_cast<char *>( str); ^

compilation aborted for cc.cc (code 2) [dcb@localhost src]$

One compiler must be wrong.

*/

Comment 1 Wolfgang Bangerth 2004-02-20 21:30:30 UTC

5.2.11/1 clearly states that the result of a const_cast is of type T. In your case, it is a char*, so it is not an lvalue. Thus, gcc must be wrong. Note also 5.2.11/4.

W.

Comment 2 Giovanni Bajo 2004-02-23 01:42:52 UTC

Agreed, GCC is wrong here.

Comment 3 Giovanni Bajo 2004-06-06 03:36:58 UTC

Retargeting to 3.4.1, being a regression on that release branch.

Comment 4 Mark Mitchell 2004-06-09 19:11:46 UTC

Working on a fix.

Comment 7 Mark Mitchell 2004-06-10 14:30:18 UTC

Fixed in GCC 3.4.1.

Comment 8 Mark Mitchell 2004-06-10 14:30:43 UTC

*** Bug 15076 has been marked as a duplicate of this bug. ***