GNOME Bugzilla – Bug 736847
Fix build of demos/gtk-demo/example_headerbar.cc on Visual Studio
Last modified: 2014-09-19 06:53:14 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...
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!
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);
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 ]
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.
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.
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!
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!
(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.
Hello Kjell, Thanks for the reviews, the patch was pushed as 62a630a2. I will close the bug now. With blessings, thank you!