After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 756593 - gmmproc: Writing custom move constructor is not possible
gmmproc: Writing custom move constructor is not possible
Status: RESOLVED FIXED
Product: glibmm
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2015-10-14 21:24 UTC by Marcin Kolny (IRC: loganek)
Modified: 2016-05-25 11:31 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
proposed solution (1.85 KB, patch)
2015-10-14 21:25 UTC, Marcin Kolny (IRC: loganek)
none Details | Review
documentation (1.21 KB, patch)
2015-10-15 13:41 UTC, Marcin Kolny (IRC: loganek)
none Details | Review
documentation v2 (1.21 KB, patch)
2015-10-15 13:43 UTC, Marcin Kolny (IRC: loganek)
none Details | Review

Description Marcin Kolny (IRC: loganek) 2015-10-14 21:24:04 UTC
Sometimes we might need use custom fields in Glib::Object-based classes, e.g. of type std::unique_ptr. Then we need explicit move this field to another object.
For now it's impossible, because we're not able to provide custom implementation of move constructor and move assignment operator. My patch solves this problem, by adding one more macro _CUSTOM_MOVE_OPERATIONS.
Comment 1 Marcin Kolny (IRC: loganek) 2015-10-14 21:25:04 UTC
Created attachment 313338 [details] [review]
proposed solution
Comment 2 Murray Cumming 2015-10-15 07:03:18 UTC
Sure. This seems analogous to the existing need for custom constuctors. Please go ahead.

But please also try to document this in gtkmm-documentation's gmmproc chapter.
Comment 3 Marcin Kolny (IRC: loganek) 2015-10-15 13:41:28 UTC
Created attachment 313371 [details] [review]
documentation

OK, I also documented my change in gtkmm-documentation. Please review, and if everything is ok, I'll push both patches to upstream repository.
Comment 4 Marcin Kolny (IRC: loganek) 2015-10-15 13:43:05 UTC
Created attachment 313373 [details] [review]
documentation v2

(minor fix)
Comment 5 Kjell Ahlstedt 2015-11-01 18:48:23 UTC
When I studied your documentation patch, I noticed that no _CUSTOM_* macros
were mentioned in the gtkmm tutorial. Now I've added very short descriptions
of them.
https://git.gnome.org/browse/gtkmm-documentation/commit/?id=9fe25ec87058685dffcc0ff7d7dbb54c30466276

My descriptions don't contain code snippets. If you want a code snippet in the
description of _CUSTOM_MOVE_OPERATIONS that's ok, but it should contain a
call to _CLASS_GOBJECT. _CUSTOM_MOVE_OPERATIONS doesn't do anything wihout
a _CLASS_GOBJECT, does it?

The gmmproc patch looks ok. But wouldn't _CUSTOM_MOVE_OPERATIONS be more
useful in _CLASS_GTKOBJECT in gtkmm? If I haven't misunderstood something,
move operations are not useful for objects which are accessed via Glib::RefPtr
(see bug 756962, part of comment 0). And most or all _CLASS_GOBJECT classes
are accessed via RefPtr.
Comment 6 Marcin Kolny (IRC: loganek) 2016-03-22 20:34:03 UTC
(In reply to Kjell Ahlstedt from comment #5)
> My descriptions don't contain code snippets. If you want a code snippet in
> the
> description of _CUSTOM_MOVE_OPERATIONS that's ok, but it should contain a
> call to _CLASS_GOBJECT. _CUSTOM_MOVE_OPERATIONS doesn't do anything wihout
> a _CLASS_GOBJECT, does it?
Correct. My mistake. 

> The gmmproc patch looks ok. But wouldn't _CUSTOM_MOVE_OPERATIONS be more
> useful in _CLASS_GTKOBJECT in gtkmm? If I haven't misunderstood something,
> move operations are not useful for objects which are accessed via
> Glib::RefPtr
> (see bug 756962, part of comment 0). And most or all _CLASS_GOBJECT classes
> are accessed via RefPtr.
I do agree; most _CLASS_GOBJECT classes are accessed via RefPtr. But as you pointed in your comment (bug 756962), we might have a situation:
 some_object11->operator=(std::move(*some_object22.operator->()));
We might also consider add _CUSTOM_MOVE_OPERATIONS to boxed types, and as you already mentioned, to GTKOBJECT.
Comment 7 Kjell Ahlstedt 2016-03-25 13:30:36 UTC
If you see a need for _CUSTOM_MOVE_OPERATIONS in _CLASS_GOBJECT or in other
types of classes, feel free to add it.
Comment 8 Marcin Kolny (IRC: loganek) 2016-04-01 20:11:07 UTC
For now I've added it only to _CLASS_GOBJECT. If someone needs it in other classes, then I'll add the same code to other files as well. 

https://git.gnome.org/browse/glibmm/commit/?id=fa77097d794e2979f60eadf94c2ed101f6455f79

https://git.gnome.org/browse/gtkmm-documentation/commit/?id=208ba72b7474516e7d8e4e17eeb4d69e2d5e6a84
Comment 9 Murray Cumming 2016-04-10 14:10:54 UTC
Thanks. Closing then.
Comment 10 Kjell Ahlstedt 2016-05-25 06:59:03 UTC
Reopening, because _CUSTOM_MOVE_OPERATIONS does not work if the class
implements an interface. I noticed this when I tried to build gtkmm-2 with
the latest gmmproc. (I know it's always a challenge to build gtkmm-2 like that.)
The bug can show up even without involving gtkmm-2. I tested by adding
_CUSTOM_MOVE_OPERATIONS in gio/src/application.hg, which implements ActionGroup
and ActionMap. The last few lines in application.cc become

} // namespace Gio


  , ActionGroup(std::move(src))
  , ActionMap(std::move(src))
  ActionGroup::operator=(std::move(src));
  ActionMap::operator=(std::move(src));

Of course it won't compile.
Comment 11 Kjell Ahlstedt 2016-05-25 11:31:14 UTC
Fixed by this commit: https://git.gnome.org/browse/glibmm/commit/?id=02f7016cc4cc96e2f85654a4fe80bd80c63b275e

The bug was in tools/m4/base.m4 and has existed for many years.
Perhaps this is the first time it has caused a real problem.
The code pushed to SECTION_CC_MOVE_CONSTRUCTOR_INTERFACES and
SECTION_CC_MOVE_ASSIGNMENT_OPERATOR_INTERFACES by _IMPLEMENTS_INTERFACE_CC in
class_shared.m4 must be discarded, if it's not imported somewhere, e.g. by
_END_CLASS_GOBJECT in class_gobject.m4.