This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Bogus error message? (covariant return types)
- To: egcs at cygnus dot com
- Subject: Bogus error message? (covariant return types)
- From: Omar Loggiodice <ologgio at vrainn dot com>
- Date: Thu, 18 Dec 1997 13:29:16 -0500 (EST)
- Reply-To: egcs at cygnus dot com
Hi folks,
First, let me say again (this time in public) that the egcs team has
done a tremendous job with egcs. Thanks for your persistance and for the
good job you're doing.
Now to the potential bug. If I compile the following code with egcs-1.0
(plus H.J. patches for RedHat 5.0) I get an error message saying:
covariant-bug1.cc:26: sorry, not implemented:
adjusting pointers for covariant returns
However, if I change the order of the base classes the code compiles and
runs perfectly.
Here is the code that shows the bug:
#include <iostream.h>
class A
{
public:
virtual A* who()
{
cout << "I'm A" << endl;
return this;
}
};
class B
{
};
// If we switch the order of the base classes egcs-1.0 doesn't
// have any problem with the covariant return type
class C:public B,public A
{
virtual C* who()
{
cout << "I'm C" << endl;
return this;
}
};
void main()
{
A* ap;
A a;
C c;
ap = &a;
ap->who();
ap = &c;
ap->who();
}
Here is the workaround:
1:26pm linda
~/tmp --> diff -u covariant-bug1.cc covariant-bug1-workaround.cc
--- covariant-bug1.cc Thu Dec 18 13:24:41 1997
+++ covariant-bug1-workaround.cc Thu Dec 18 13:25:16 1997
@@ -14,9 +14,9 @@
{
};
-// If we switch the order of the base classes egcs-1.0 doesn't
-// have any problem with the covariant return type
-class C:public B,public A
+// After switching the order of the base classes egcs-1.0 doesn't
+// have any problem compiling this code
+class C:public A,public B
{
virtual C* who()
{
And everything works fine using the workaround:
~/tmp --> g++ covariant-bug1-workaround.cc
1:27pm linda
~/tmp --> ./a.out
I'm A
I'm C
1:27pm linda
~/tmp -->
Here's the output of g++ -v:
~/tmp --> g++ -v
Reading specs from
/usr/local/lib/gcc-lib/i586-pc-linux-gnu/egcs-2.90.21/specs
gcc version egcs-2.90.21 971202 (egcs-1.00 release)
____________________________________________________________________
/ __ __ __ - __ __ / - _ __ ologgio@vrainn.com
Omar R. /__ /_/ /_/ /_/ / /_/ /_/ / /_ /-_ CIS: 74040,1543
__/ __/
___C++/7_yrs____Virtual Reality/4_yrs____Vorl_____Linux(free)_______
PCCTS instead of YACC - LL(k) grammars, infinite look-ahead