GNOME Bugzilla – Bug 132300
G++-3.4 Prerelease: Private copy constructor for Glib::ConstructParams.
Last modified: 2004-12-22 21:47:04 UTC
The following code: #include <gtkmm/treemodelcolumn.h> #include <gtkmm/treeviewcolumn.h> int main(int argc, char *argv[]) { Gtk::TreeModelColumn<int> col; Gtk::TreeViewColumn col2("A", col); } gives these errors in G++-3.4: /usr/include/gtkmm-2.0/glibmm/object.h: In constructor `Gtk::TreeViewColumn::TreeViewColumn(const Glib::ustring&, const Gtk::TreeModelColumn<ColumnType>&) [with T_ModelColumnType = int]': private2.cc:7: instantiated from here /usr/include/gtkmm-2.0/glibmm/object.h:76: error: `Glib::ConstructParams::ConstructParams(const Glib::ConstructParams&)' is private /usr/include/gtkmm-2.0/gtkmm/treeviewcolumn.h:674: error: within this context apparently this is because of this code: template <class T_ModelColumnType> TreeViewColumn::TreeViewColumn(const Glib::ustring& title, const TreeModelColumn<T_ModelColumnType>& column) : Glib::ObjectBase(0), // not (yet) a custom class Gtk::Object(Glib::ConstructParams(class_init_(), "title", title.c_str(), (char*) 0)) { pack_start(column, true /* expand */); } Apparently the Glib::ConstructParams needs to be copyable. This is something to do with passing a reference to a temporary. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12226 was mentioned as related. I imagine this is quite common in Gtkmm but I think this is the only instance in a header as its a template. Not sure about workarounds here if copy construction is unacceptable, perhaps making the params into a member variable would solve the problem. Here's a test case of this, works in 3.2/3.3 but not 3.4: struct A { A(const char* p, ...); private: A(const A&); }; struct B { B(const A&); }; int main(int argc, char *argv[]) { B b( A("title", (char*) 0) ); }
Thanks. Let's try to deal with these before the API freeze, because we might not be able to deal with them afterwards.: http://www.gnome.org/start/2.5/bindings/
danielk didn't mention it here, but he did some stuff with this, introducing a copy constructor, not tested yet. You probably don't actually need to write the constructor though, just make it public. Because G++ probably optimises it out, it probably never gets actually called, just checked. So it might work like the private constructor trick, you don't need to supply the body if it's never used. Might not be a good idea to rely on this though.
Any chance of a patch?
I have added the public copy constructor in cvs. Thanks.
As it happens I had already written a little patch to fix this when Matthew first told me about the problem, which then got lost due to my long absence from gtkmm development. Anyway, I stumbled over this issue again today and noticed that the current solution doesn't implement the copy constructor properly, thus in effect relying on the call being optimized away by the compiler. To fix this pontential problem, I now committed my older patch to both the glibmm and the gtkmm2 module: 2004-05-13 Daniel Elstner <daniel.elstner@gmx.net> * glib/glibmm/object.{cc,h} (ConstructParams::ConstructParams): Implement the copy constructor in a way that actually works if used. Relying on the compiler to optimize it away is a bad idea. (#132300)