This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Example of covaraint return fix [PR 3706]


This is a follow up to my patch post; Brane Čibej made the (excellent)
suggestion that I post an example.

Using gcc 3.1 on i686-linux-pc with the patch applied, this code :

#include <iostream>

class Test
{
private:
   int i;

public:
   virtual Test *GetThis() = 0;
};

class Test2 : virtual public Test
{
public:
   Test2();
   virtual Test2 *GetThis();
};

Test2::Test2()
{
   std::cout << "Test2 as Test         -> ";
   std::cout << (void*)static_cast<Test *> ( this ) << std::endl;
   std::cout << "Test2 as Test2        -> ";
   std::cout << (void*)this << std::endl;
}

Test2 *Test2::GetThis()
{
   return this;
}

int main ( int argc, char *argv[], char *envp[] )
{
   Test2  OBJ;
   Test2 *P2;
   Test * P;

   P2 = OBJ.GetThis();
   std::cout << "From Test2::GetThis() -> ";
   std::cout << (void *)P2 << std::endl;

   P = &OBJ;
   P = P->GetThis();
   std::cout << "From Test::GetThis()  -> ";
   std::cout << (void *)P << std::endl;

   return 0;
}

produces the following output :

Test2 as Test         -> 0xbffffa28
Test2 as Test2        -> 0xbffffa24
>From Test2::GetThis() -> 0xbffffa24
>From Test::GetThis()  -> 0xbffffa28

Without the patch you get :

check.cc:13: sorry, not implemented: adjusting pointers for covariant
returns

Again, I would appreciate any information and help in cleaning this code
up and bringing it up to coding standards for GCC. I need this patch for
what I'm working on, but I would like to have it in a form conforming to
prevailing code practices in GCC in case I need to fit it into a
different release.

Thank you!

--- David Hunt
--- hunt.d@attbi.com 

Attachment: check.cc
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]