[GCC-XML] Failed to compile pimpl idiom with up to date gccxml and boost's scoped_ptr

Kirill Lapshin kir at lapshin.net
Mon Jan 5 12:14:29 EST 2009


Hello,

I've just subscribed to this list, so please be gentle.

I was using gccxml for awhile, and I am quite happy and satisfied 
customer. Thanks a lot to everybody who put hard work into this 
extremely useful software.

Recently I've tried to port my project to most recent Ubuntu (8.10). It 
comes with gcc 4.3 and a bit outdated gccxml, which unfortunately 
doesn't support 4.3. Nothing new, I've seen similar problems before and 
will certainly file a bug with Ubuntu on this. Next thing I've tried is 
to compile my own version of gccxml from CVS head. That does add 4.3 
support but has some funky problems. Here is a simple C++ example that 
triggers the bug (?):

-----------------
#include <boost/scoped_ptr.hpp>

class foo
{
public:
   
    foo();
    ~foo();
   
private:
    struct impl;
    boost::scoped_ptr<impl> pimpl;
};
----------------

If I run 'gccxml foo.cpp' it doesn't complain at all, but if I do 
'gccxml foo.cpp -fxml=foo.xml', then I get following errors:

/usr/include/boost/checked_delete.hpp: In function 'void 
boost::checked_delete(T*) [with T = foo::impl]':
/usr/include/boost/scoped_ptr.hpp:77:   instantiated from 
'boost::scoped_ptr<T>::~scoped_ptr() [with T = foo::impl]'
foo.cpp:4:   instantiated from here
/usr/include/boost/checked_delete.hpp:32: error: invalid application of 
'sizeof' to incomplete type 'foo::impl'
/usr/include/boost/checked_delete.hpp:32: error: creating array with 
negative size ('-0x00000000000000001')
/usr/include/boost/checked_delete.hpp:33: error: invalid application of 
'sizeof' to incomplete type 'foo::impl'
/usr/include/boost/checked_delete.hpp:33: error: creating array with 
negative size ('-0x00000000000000001')
/usr/include/boost/checked_delete.hpp:34: note: neither the destructor 
nor the class-specific operator delete will be called, even if they are 
declared when the class is defined.

Interestingly the foo.xml is produced, and looks ok to me.

I think this is a bug, because
1. g++ compiles it fine
2. There is no reason for scoped_ptr's destructor to be instantiated 
here, as it should be instantiated at the point where ~foo() is defined 
(which is supposedly in different translation unit). That's standard 
pimpl idiom which is used quite extensively.

Another interesting observation is that we don't observe this problem 
with older gccxml versions. Not sure when it was introduced -- I'll try 
to pick some older version to see if it solves this problem.

Regards,

Kirill




More information about the gccxml mailing list