public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/5607: No pointer adjustment in covariant return types
@ 2002-09-14 15:54 nathan
  0 siblings, 0 replies; 2+ messages in thread
From: nathan @ 2002-09-14 15:54 UTC (permalink / raw)
  To: AlexanderRozenman, gcc-bugs, gcc-prs, nobody, shure

Synopsis: No pointer adjustment in covariant return types

State-Changed-From-To: open->closed
State-Changed-By: nathan
State-Changed-When: Sat Sep 14 15:54:26 2002
State-Changed-Why:
    dup of 3706, modulo jason's patch

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5607


^ permalink raw reply	[flat|nested] 2+ messages in thread

* c++/5607: No pointer adjustment in covariant return types
@ 2002-02-06  2:56 AlexanderRozenman
  0 siblings, 0 replies; 2+ messages in thread
From: AlexanderRozenman @ 2002-02-06  2:56 UTC (permalink / raw)
  To: gcc-gnats; +Cc: shure


>Number:         5607
>Category:       c++
>Synopsis:       No pointer adjustment in covariant return types
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 06 02:56:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Alex Rozenman
>Release:        gcc 3.0
>Organization:
>Environment:
Solaris 2.6
>Description:
When you run the attached program you can see that
pointer to B instance before and after covariant return
are different.

This is copy of my test case (the same as the attached file):

#begin

/**
 * This is test case for covariant pointers 
 * compiler implementation.
 * Numbers in each result line should be
 * the same.
 */

#include <iostream.h>

class A {
public:
  virtual A* getThis() { return this; }
};

class B {
int a;
public:
  virtual B* getThis() { return this; }
};

class AB : public A, public B {
public:
  virtual AB* getThis() { return this; }
};


int main () {

  using namespace std;

  AB* ab = new AB();
  
  A* a = ab;
  B* b = ab;

  cout << a << " " << a->getThis() <<  endl;
  cout << b << " " << b->getThis() <<  endl;

  return 0;
}

#end
>How-To-Repeat:
Compile the test case, run it. 
In the second line you can see two different 
pointers to the same instance ('B' in the program)
>Fix:
Adjust the pointer appropriately
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="Covariant.cpp"
Content-Disposition: inline; filename="Covariant.cpp"


/**
 * This is test case for covariant pointers 
 * compiler implementation.
 * Numbers in each result line should be
 * equal. 
 */

#include <iostream.h>

class A {
public:
  virtual A* getThis() { return this; }
};

class B {
int a;
public:
  virtual B* getThis() { return this; }
};

class AB : public A, public B {
public:
  virtual AB* getThis() { return this; }
};


int main () {

  using namespace std;

  AB* ab = new AB();
  
  A* a = ab;
  B* b = ab;

  cout << a << " " << a->getThis() <<  endl;
  cout << b << " " << b->getThis() <<  endl;

  return 0;
}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-09-14 22:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-14 15:54 c++/5607: No pointer adjustment in covariant return types nathan
  -- strict thread matches above, loose matches on Subject: below --
2002-02-06  2:56 AlexanderRozenman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).