[Bug c++/12819] New: ICE during compile when trying to obtain object method address

fryman at cc dot gatech dot edu gcc-bugzilla@gcc.gnu.org
Wed Oct 29 01:47:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: ICE during compile when trying to obtain object method
                    address
           Product: gcc
           Version: 3.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fryman at cc dot gatech dot edu
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: sparc-sun-solaris2.8
  GCC host triplet: sparc-sun-solaris2.8
GCC target triplet: sparc-sun-solaris2.8

Trying to obtain the object method address in an exercise.  Compiler ICEs.
Attaching the ".i" file as per instructions would be stupid, since I use
"#include <iostream>".  attached are the very short C++ files that generate
the problem.  header file: hw3.hxx, source file: hw3.cxx.  command line args
to build:

g++ -g -O -save-temps -o hw3 hw3.cxx

error output:

hw3.cxx: In member function `virtual void C3::C0_m_a()':
hw3.cxx:49: Internal compiler error in decay_conversion, at cp/typeck.c:1679
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions.
*** Error code 1
make: Fatal error: Command failed for target `hw3'


===============================
FILE 1: hw3.hxx
===============================
#ifndef _hw3_h_
#define _hw3_h_

class C0
{
   public:
      int C0_d_a;
      virtual void C0_m_a( void );
};

class C1
{
   public:
     int C1_d_a;
     virtual void C1_m_a( void );
};


class C2 : public C1
{
   public:
     int C2_d_a;
     virtual void C2_m_a( void );
};

class C3 : public C2, public C0
{
   public:
    int C3_d_a;
    virtual void C3_m_a( void );
    virtual void C0_m_a( void );
};

#endif


===============================
FILE 2: hw3.cxx
===============================
#include <iostream>

#include "hw3.hxx"

using namespace std;

void
C0::C0_m_a( void )
{
   void * pthis = this, * pdata = &C0_d_a;
   
   cout << "C0_m_a: this = " << pthis << " C0_d_a at addr " << pdata << endl;
}

void 
C1::C1_m_a( void )
{
   void * pthis = this, * pdata = &C1_d_a;
   
   cout << "C1_m_a: this = " << pthis << " C1_d_a at addr " << pdata << endl;
}


void 
C2::C2_m_a( void )
{
   void * pthis = this, * pdata = &C2_d_a;
   
   cout << "C2_m_a: this = " << pthis << " C2_d_a at addr " << pdata << endl;
}


void 
C3::C3_m_a( void )
{
   void * pthis = this, * pdata = &C3_d_a;
   
   cout << "C3_m_a: this = " << pthis << " C3_d_a at addr " << pdata << endl;
}

void
C3::C0_m_a( void )
{
   void * pthis = this, * pdata = &C0_d_a, * pmethod;
   void (C3::*pmeth)( void ) = &C3::C0_m_a;
   
   cout << "C3 overload C0_m_a: this = " << pthis << " C3 overload C0_d_a at
addr " << pdata << endl;
   
   pmethod = (void*)*(this->*pmeth);
   cout << "C3's C0_m_a is at " << pmethod << endl;
}


int main( void )
{

   C3 * c3 = new C3();
   C2 * c2;
   C1 * c1;
   C0 * c0;
   int * vtable;
   void * pc1, * pc2, * pc3, * pc0;
   
   cout << endl << endl;
   
   cout << "Vanilla pointer check..." << endl;
   c2 = c3;
   c1 = c3;
   c0 = c3;
   cout << "C3ptr = " << c3 << ", C2ptr to C3 = " << c2 << ", C1ptr to C3 = " <<
c1 << ", C0ptr to C3 = " << c0 <<endl << endl; 
   
   cout << "Casted pointer check..." << endl;
   c2 = (C2*)c3;
   c1 = (C1*)c3;
   c0 = (C0*)c3;
   cout << "C3ptr = " << c3 << ", C2ptr to C3 = " << c2 << ", C1ptr to C3 = " <<
c1 << ", C0ptr to C3 = " << c0 <<endl << endl; 
   
   cout << "Void pointer check..." << endl;
   pc3 = (void*)c3;
   pc2 = (void*)c2;
   pc1 = (void*)c1;
   pc0 = (void*)c0;
   cout << "C3ptr = " << c3 << ", C2ptr to C3 = " << c2 << ", C1ptr to C3 = " <<
c1 << ", C0ptr to C3 = " << c0 <<endl << endl; 

   cout << "Calling methods from C0ptr" << endl;
   c0->C0_m_a();
   cout << endl;

   cout << "Calling methods from C1ptr" << endl;
   c1->C1_m_a();
   cout << endl;

   cout << "Calling methods from C2ptr" << endl;
   c2->C2_m_a();
   c2->C1_m_a();
   cout << endl;
   
   cout << "Calling methods from C3ptr" << endl;
   c3->C3_m_a();
   c3->C2_m_a();
   c3->C1_m_a();
   c3->C0_m_a();
   c3->C0::C0_m_a();
   cout << endl;
   
   cout << "C3ptr's VTABLE looks like this... " << endl;
   vtable = (int*)c3;
   for (int i=0; i<3; i++)
      cout << "\tmethod " << i << " = " << (int*)(*(((int*)(*vtable))+i)) << endl;
   cout << endl;
   

   cout << "C0ptr's VTABLE looks like this... " << endl;
   vtable = (int*)c0;
   for (int i=0; i<1; i++)
      cout << "\tmethod " << i << " = " << (int*)(*(((int*)(*vtable))+i)) << endl;
   cout << endl;
   
   
   cout << "done..." << endl << endl;
   
   return 0;
}


===============================
FILE 3: Makefile
===============================

CC      = gcc
CFLAGS  = -g -O
CXX     = g++ 
#CXX    = g++-2.95.2
CXFLAGS = -g -O -save-temps

default: hw3
        ./hw3

clean: 
        rm -f *.o *~ *.bak hw3

hw3: hw3.cxx hw3.hxx
        $(CXX) $(CXFLAGS) -o $@ hw3.cxx



More information about the Gcc-bugs mailing list