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 736847 - Fix build of demos/gtk-demo/example_headerbar.cc on Visual Studio
Fix build of demos/gtk-demo/example_headerbar.cc on Visual Studio
Status: RESOLVED FIXED
Product: gtkmm
Classification: Bindings
Component: general
3.13.x
Other Windows
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2014-09-18 06:14 UTC by Fan, Chun-wei
Modified: 2014-09-19 06:53 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix build of example_headerbar.cc on Visual Studio (1.21 KB, patch)
2014-09-18 06:18 UTC, Fan, Chun-wei
none Details | Review
Fix build of example_headerbar.cc (1.14 KB, patch)
2014-09-19 04:20 UTC, Fan, Chun-wei
none Details | Review
Fix build of example_headerbar.cc (1.49 KB, patch)
2014-09-19 04:26 UTC, Fan, Chun-wei
committed Details | Review

Description Fan, Chun-wei 2014-09-18 06:14:37 UTC
Hi,

As later Visual Studio versions (2005+ or so) are quite picky about types and casting, example_headerbar.cc would fail to build on the Visual Studio builds that is currently supported by gtkmm, due to an ambiguous call to m_send_receive_image.set().  I will attach a patch that attempts to fix this...
Comment 1 Fan, Chun-wei 2014-09-18 06:18:35 UTC
Created attachment 286441 [details] [review]
Fix build of example_headerbar.cc on Visual Studio

Hi,

This is my patch on fixing the build of example_headerbar.cc on Visual Studio.

With blessings, thank you!
Comment 2 Kjell Ahlstedt 2014-09-18 09:04:35 UTC
C-style casts are not very nice. More or less equivalent to reinterpret_cast.
Applied to Glib::RefPtr objects they can be more risky than usual, I think,
even though I'm sure it would work in this case.

Does Visual Studio accept any of these alternatives?

1.
  Glib::RefPtr<Gio::Icon> icon =
    Gio::ThemedIcon::create("mail-send-receive-symbolic", false);
  m_send_receive_image.set(icon, Gtk::ICON_SIZE_BUTTON);

2.
  Glib::RefPtr<Gio::ThemedIcon> icon =
    Gio::ThemedIcon::create("mail-send-receive-symbolic", false);
  m_send_receive_image.set(Glib::RefPtr<Gio::Icon>::cast_static(icon),
    Gtk::ICON_SIZE_BUTTON);
Comment 3 Fan, Chun-wei 2014-09-18 10:57:38 UTC
Hello Kjell,

From what I could tell, a variant of 1 or 2 can be done (it's picky about the "const" part, somehow), i.e.:

1a:
Glib::RefPtr<const Gio::Icon> icon =
    Gio::ThemedIcon::create("mail-send-receive-symbolic", false);

-or-

2a:
m_send_receive_image.set(Glib::RefPtr<const Gio::Icon>::cast_static(icon),
    Gtk::ICON_SIZE_BUTTON);

Let me know which route is preferred.

With blessings, thank you!

p.s. the error I had was like:
.\demos\gtk-demo\example_headerbar.cc(85): error C2668: 'Gtk::Image::set' : ambiguous call to overloaded function
          C:\gnome.build.unstable\gtkmm-3.13.8\gtk\gtkmm/image.h(307): could be 'void Gtk::Image::set(const Glib::RefPtr<T_CppObject> &,Gtk::IconSize)'
          with
          [
              T_CppObject=const Gio::Icon
          ]
          C:\gnome.build.unstable\gtkmm-3.13.8\gtk\gtkmm/image.h(289): or       'void Gtk::Image::set(const Glib::RefPtr<T_CppObject> &,Gtk::IconSize)'
          with
          [
              T_CppObject=Gtk::IconSet
          ]
          while trying to match the argument list '(Glib::RefPtr<T_CppObject>, Gtk::BuiltinIconSize)'
          with
          [
              T_CppObject=Gio::ThemedIcon
          ]
Comment 4 Kjell Ahlstedt 2014-09-18 14:02:20 UTC
I'm surprised that Visual Studio considers
  void Gtk::Image::set(const Glib::RefPtr<IconSet>& icon_set, IconSize size)
a viable function during the overload resolution. A Gio::Icon or
Gio::ThemedIcon is not a Gtk::IconSet. It looks like the compiler does not
care enough about RefPtr's template parameter in this part of the overload
resolution. I can't say if it's according to the C++ standard. Overload
resolution is a tricky part of C++ with sometimes surprising results.

Since it's 'const' that's important in order to make the call unambiguous,
perhaps this might do:

3.
  Glib::RefPtr<const Gio::ThemedIcon> icon =
    Gio::ThemedIcon::create("mail-send-receive-symbolic", false);
  m_send_receive_image.set(icon, Gtk::ICON_SIZE_BUTTON);

I prefer that one, if Visual Studio accepts it, otherwise your 1a.
You might also add a comment, explaining that the seemingly unnecessary
'const' is necessary. Or else someone might remove it in the future.
Comment 5 Kjell Ahlstedt 2014-09-18 18:20:30 UTC
I tried to compile with gcc and GTKMM_DISABLE_DEPRECATED undefined. Then gcc
reacts like Visual Studio. The call to Gtk::Image::set() is ambiguous unless
the first parameter is an exact match, i.e. it's Glib::RefPtr<const Gio::Icon>.

My alternative 3 does not compile with gcc, your alternative 1a does.
Probably Visual Studio will also refuse alt. 3.
Conclusion: Choose 1a.

Usually when the demos and test cases are compiled on Linux,
GTKMM_DISABLE_DEPRECATED is defined, and then
  void Gtk::Image::set(const Glib::RefPtr<IconSet>& icon_set, IconSize size)
is not an alternative, as Gtk::IconSet is deprecated.
Comment 6 Fan, Chun-wei 2014-09-19 04:20:55 UTC
Created attachment 286549 [details] [review]
Fix build of example_headerbar.cc

Hello Kjell,

Indeed, option 3 does not work.  This is the patch going the option 1a route.

With blessings, thank you!
Comment 7 Fan, Chun-wei 2014-09-19 04:26:31 UTC
Created attachment 286557 [details] [review]
Fix build of example_headerbar.cc

Hi,

I forgot to added the suggested comment.  So here it comes again.

With blessings, thank you!
Comment 8 Kjell Ahlstedt 2014-09-19 06:39:59 UTC
(In reply to comment #5)
> Usually when the demos and test cases are compiled on Linux,
> GTKMM_DISABLE_DEPRECATED is defined

Correction: GTKMM_DISABLE_DEPRECATED is defined in gtkmm/demos, but it's
not defined in gtkmm/tests. See the Makefile.am files.


(In reply to comment #7)
The patch looks good. Please push it.
Comment 9 Fan, Chun-wei 2014-09-19 06:53:02 UTC
Hello Kjell,

Thanks for the reviews, the patch was pushed as 62a630a2.  I will close the bug now.

With blessings, thank you!