Bug 19891 - [4.0 Regression] Covariant returns are broken
Summary: [4.0 Regression] Covariant returns are broken
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Nathan Sidwell
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-02-11 01:45 UTC by benjamin.redelings
Modified: 2005-02-14 09:41 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 3.4.0
Known to fail: 4.0.0 3.3.3
Last reconfirmed: 2005-02-11 13:30:49


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description benjamin.redelings 2005-02-11 01:45:14 UTC
Here is a testcase that fails in 4.0 CVS, but works in 3.4.

--------------------
extern "C" void printf (const char*, ...);
struct Model {
  bool full_tree;      // if you remove this, the error goes away
  virtual Model* clone() const =0;
  virtual char *name() const =0;
  virtual ~Model() {}  // if you remove this, the error goes away
};
struct R: virtual public Model {
  virtual R* clone() const =0;
};
struct A: virtual public Model {
  virtual A* clone() const=0;
};
struct RA: public R, public A {
  virtual RA* clone() const=0;
};
//--------------------- EQU  Model ------------------------//
struct EQU: public RA {
  virtual EQU* clone() const {return new EQU(*this);}
  char *name() const {return "EQU";}
};
int main() {
  Model* M1 = new EQU();
  Model* M2 = M1->clone();
  Model* M3 = M2->clone();
  printf("subst model = %s \n", M1->name() );
  printf("subst model = %s \n", M2->name() );
  printf("subst model = %s \n", M3->name() );


  return 0;
}
Comment 1 Andrew Pinski 2005-02-11 04:42:53 UTC
Confirmed.  Note covariant returns were not implemented for 3.3.3 so we just gave an error.
Comment 2 GCC Commits 2005-02-14 09:36:50 UTC
Subject: Bug 19891

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	nathan@gcc.gnu.org	2005-02-14 09:36:35

Modified files:
	gcc/cp         : ChangeLog class.c search.c typeck.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/abi: covariant4.C 

Log message:
	cp:
	PR c++/19891
	* class.c (build_simple_base_path): Build the component_ref
	directly.
	(update_vtable_entry_for_fn): Walk the covariant's binfo chain
	rather than using lookup_base.
	* search.c (dfs_walk_once): Add non-recursive assert check.
	* typeck.c (build_class_member_access_expr): It is possible for
	the member type to be both const and volatile.
	testsuite:
	PR c++/19891
	* g++.dg/abi/covariant4.C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4625&r2=1.4626
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&r1=1.703&r2=1.704
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&r1=1.344&r2=1.345
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.613&r2=1.614
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5028&r2=1.5029
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/abi/covariant4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 3 Nathan Sidwell 2005-02-14 09:41:58 UTC
2005-02-11  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/19891
	* class.c (build_simple_base_path): Build the component_ref
	directly.
	(update_vtable_entry_for_fn): Walk the covariant's binfo chain
	rather than using lookup_base.
	* search.c (dfs_walk_once): Add non-recursive assert check.
	* typeck.c (build_class_member_access_expr): It is possible for
	the member type to be both const and volatile.