This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: 3.4.0 vs 3.3.3
- From: "Giovanni Bajo" <giovannibajo at libero dot it>
- To: "Shelly Adhikari" <shelly at interrasystems dot com>,<gcc at gcc dot gnu dot org>
- Date: Wed, 21 Apr 2004 02:19:20 +0200
- Subject: Re: 3.4.0 vs 3.3.3
- References: <40858A64.4090806@InterraSystems.com>
Shelly Adhikari wrote:
> Should I file a bug against gcc 3.4.0, the following compiles fine
> with gcc 3.3.3 but gives errors with gcc 3.4.0.
>
> -----------------------------------------------------------------------------
----------------------------------------------
> template <class A> class C;
>
> template <class A> class B {
> public:
> B() { }
> ~B() { }
> protected:
> int abc;
> void g() {}
> friend void C<A>::f(B<A>* p);
> };
>
> template <class A> class C : public B<A> {
> public:
> void f(B<A>* p) {
> p->g();
> int m = p->abc;
> }
> };
>
> int main() {
> B<int>* y = new B<int>();
> C<int> x;
> x.f(y);
> }
> -----------------------------------------------------------------------------
----------------------------------------------
The code is ill-formed: the instantiation of B<int> triggers an instantiation
of C<int> in the friend declaration, which in turns triggers another
instantiation of B<int> (as base member). The recursion is detected and
compilation is stopped (in fact, while instatiating C<int>, B<int> is still
incomplete).
This probably happens due to some patches to handle the friend declarations
better.
Giovanni Bajo