Bug 235008

Summary: Bad compilation error message when on casting a constant pointer
Product: Red Hat Enterprise Linux 4 Reporter: cb <cyrilbesse1>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED ERRATA QA Contact:
Severity: low Docs Contact:
Priority: medium    
Version: 4.0CC: aoliva
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: RHBA-2007-0803 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2007-11-15 16:08:48 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
gcc34-rh235008.patch none

Description cb 2007-04-03 09:07:54 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3

Description of problem:
When I compile this code, I obtain an internal error of compiler.
I whould like a simple error message.

#include <assert.h>
class AA
{
  int i;
};

class AB : public AA
{
public:
  int j;
};


void fct(const AA* a)
{
  const AB* p_ab = static_cast<AB *>(a);
  assert(p_ab->j == 2);
}

int main()
{
  AB ab;
  ab.j = 2;
  fct(&ab);

  return 0;
}


Version-Release number of selected component (if applicable):
gcc 3.4.6

How reproducible:
Always


Steps to Reproduce:
1.compile this code
2.
3.

Actual Results:
Please submit a full bug report
;-)

Expected Results:
An error message, for example: 
'invalid convertion of " AB* " to " const AB* "'

Additional info:
For information, the correct line is: 
  const AB* p_ab = static_cast<const AB *>(a);

Comment 1 Alexandre Oliva 2007-04-10 07:33:18 UTC
Can you please confirm what version of GCC you're using?  I haven't been able to
duplicate this with the U4 gcc:

$ g++ -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)
$ g++ bz235008.cc 
bz235008.cc: In function `void fct(const AA*)':
bz235008.cc:16: error: static_cast from type `const AA*' to type `AB*' casts
away constness


Comment 2 cb 2007-04-10 09:44:11 UTC
I use a french gcc version. Moreover, I use a machine virutal (VMware) for
launching Linux AS4. Perhaps thus the problem comes from their image.

$ gcc -v
Lecture des spcification  partir de /usr/lib/gcc/i386-redhat-linux/3.4.6/specs
Configur avec: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Modle de thread: posix
version gcc 3.4.6 20060404 (Red Hat 3.4.6-3)

$ make bug_gcc
g++     bug_gcc.cpp   -o bug_gcc
bug_gcc.cpp: In function `void fct(const AA*)':

erreur interne au compilateur : routine de rapport d'erreur prempte.
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccuRsD9O.out file, please attach this to
your bugreport.
make: *** [bug_gcc] Erreur 1


(In reply to comment #1)
> Can you please confirm what version of GCC you're using?  I haven't been able to
> duplicate this with the U4 gcc:
> 
> $ g++ -v
> Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs
> Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
> --infodir=/usr/share/info --enable-shared --enable-threads=posix
> --disable-checking --with-system-zlib --enable-__cxa_atexit
> --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
> Thread model: posix
> gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)
> $ g++ bz235008.cc 
> bz235008.cc: In function `void fct(const AA*)':
> bz235008.cc:16: error: static_cast from type `const AA*' to type `AB*' casts
> away constness
> 

Comment 3 Jakub Jelinek 2007-04-12 22:26:21 UTC
Created attachment 152512 [details]
gcc34-rh235008.patch

That's a translation bug.

Comment 4 RHEL Program Management 2007-07-18 18:24:57 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux maintenance release.  Product Management has requested
further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed
products.  This request is not yet committed for inclusion in an Update
release.

Comment 10 errata-xmlrpc 2007-11-15 16:08:48 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2007-0803.html