You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Aleš Trček <Al...@halcom.si> on 2013/05/20 23:23:10 UTC

Circular reference in qpidc

Hi all,

I am trying to compile qpidc 0.20 on AIX, and have come across a strange issue... Compiling the qpid/framing/AMQP_ServerProxy.o object, the compiler produces the following error:
"qpid_build/qpidc-0.20/src/qpid/framing/Handler.h", line 52.47: 1540-0407 (S) The base class "Handler" contains a circular reference back to "Functor".
The relevant code in the Handler.h header is:
31  template <class T>
32  struct Handler {
...
48      /** Adapt any void(T) functor as a Handler.
49       * Functor<F>(f) will copy f.
50       * Functor<F&>(f) will only take a reference to x.
51       */
52      template <class F> class Functor : public Handler<T> {
53        public:
54          Functor(F f, Handler<T>* next=0) : Handler<T>(next), functor(f) {}
55          void handle(T t) { functor(t); }
56        private:
57          F functor;
58      };
...

So, the struct Handler contains nested class Functor, which extends the enveloping struct. This is not possible in C++ (at least not without forward declaration) since the enveloping class is not yet complete at the time of the nested class declaration.
Simple test:
struct base
{
  int bla;

  class extended : public base
  {
  public:
    extended() {}
  };
};

int main()
{
return 0;
}

produces on AIX (xlC compiler):
"circular.cpp", line 5.27: 1540-0407 (S) The base class "base" contains a circular reference back to "extended".

and on Linux (CentOS, gcc):
circular.cpp:6: error: invalid use of incomplete type âstruct baseâ
circular.cpp:2: error: forward declaration of âstruct baseâ

I am baffled... how does this ever compile? I know it does, since I compiled it myself (0.18, few months back) on Linux :|.

Regards,
Ales

RE: Circular reference in qpidc

Posted by Aleš Trček <Al...@halcom.si>.
Hi,

Thanx, the fix is OK so this issue is resolved.

Regards,
Ales

-----Original Message-----
From: Darryl L. Pierce [mailto:dpierce@redhat.com] 
Sent: Tuesday, May 21, 2013 2:45 PM
To: users@qpid.apache.org
Subject: Re: Circular reference in qpidc

On Mon, May 20, 2013 at 09:23:10PM +0000, Aleš Trček wrote:
> Hi all,
> 
> I am trying to compile qpidc 0.20 on AIX, and have come across a strange issue... Compiling the qpid/framing/AMQP_ServerProxy.o object, the compiler produces the following error:
> "qpid_build/qpidc-0.20/src/qpid/framing/Handler.h", line 52.47: 1540-0407 (S) The base class "Handler" contains a circular reference back to "Functor".
<snip>

This popped up on my radar back in February when I started working with GCC 4.8.0 (early versions handled the code fine). I commited this fix:

commit 631f31a401f308e93303d5cc3a60f03f4c5eca34
Author: Darryl L. Pierce <mc...@apache.org>
Date:   Tue Feb 12 19:26:13 2013 +0000

    QPID-4579: Fixes building Qpid under the latest GCC (4.8.0).
    
    Moves the definition of Functor and MemFuncRef out of Handler class
    definition. Fixes the build failure in later versions of GCC.
    
    Contributed by: Petr Machata <pm...@redhat.com>
    
    git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1445322 13f79535-47bb-0310-9956-ffa450edef68

You can pull that patch and apply it on top of 0.20 to fix the issue.

--
Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc.
Delivering value year after year.
Red Hat ranks #1 in value among software vendors.
http://www.redhat.com/promo/vendor/


Re: Circular reference in qpidc

Posted by "Darryl L. Pierce" <dp...@redhat.com>.
On Mon, May 20, 2013 at 09:23:10PM +0000, Aleš Trček wrote:
> Hi all,
> 
> I am trying to compile qpidc 0.20 on AIX, and have come across a strange issue... Compiling the qpid/framing/AMQP_ServerProxy.o object, the compiler produces the following error:
> "qpid_build/qpidc-0.20/src/qpid/framing/Handler.h", line 52.47: 1540-0407 (S) The base class "Handler" contains a circular reference back to "Functor".
<snip>

This popped up on my radar back in February when I started working with
GCC 4.8.0 (early versions handled the code fine). I commited this fix:

commit 631f31a401f308e93303d5cc3a60f03f4c5eca34
Author: Darryl L. Pierce <mc...@apache.org>
Date:   Tue Feb 12 19:26:13 2013 +0000

    QPID-4579: Fixes building Qpid under the latest GCC (4.8.0).
    
    Moves the definition of Functor and MemFuncRef out of Handler class
    definition. Fixes the build failure in later versions of GCC.
    
    Contributed by: Petr Machata <pm...@redhat.com>
    
    git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1445322 13f79535-47bb-0310-9956-ffa450edef68

You can pull that patch and apply it on top of 0.20 to fix the issue.

-- 
Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc.
Delivering value year after year.
Red Hat ranks #1 in value among software vendors.
http://www.redhat.com/promo/vendor/