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]

Re: 3.4.0 vs 3.3.3


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



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