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 736778 - Avoid Ambiguous Constructor Overloads for ustring::Stringify for string literals for Visual Studio builds
Avoid Ambiguous Constructor Overloads for ustring::Stringify for string liter...
Status: RESOLVED FIXED
Product: glibmm
Classification: Bindings
Component: tests
unspecified
Other Windows
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2014-09-17 04:57 UTC by Fan, Chun-wei
Modified: 2014-09-20 12:21 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Make giomm tests runnable under Windows (2.27 KB, patch)
2014-09-17 05:10 UTC, Fan, Chun-wei
committed Details | Review
Fix build of glibmm_ustring_compose on Visual Studio (1.41 KB, patch)
2014-09-17 05:15 UTC, Fan, Chun-wei
none Details | Review
Fix build of glibmm_ustring_compose on Visual Studio (take ii) (1.46 KB, patch)
2014-09-17 11:32 UTC, Fan, Chun-wei
none Details | Review
ustring.h: Add specialization for string literals in the form of const char[N] (1.64 KB, patch)
2014-09-19 05:55 UTC, Fan, Chun-wei
committed Details | Review

Description Fan, Chun-wei 2014-09-17 04:57:50 UTC
Hi,

During the fixing and the enhancing of the Visual Studio files, there were some tests that need to be updated in order to be runnable/compiled under Windows, in particular Visual Studio builds.

I will attach patches for these items in the following posts...
Comment 1 Fan, Chun-wei 2014-09-17 05:10:53 UTC
Created attachment 286337 [details] [review]
Make giomm tests runnable under Windows

Hi,

First up is the updates to the giomm_ioerror and giomm_simple tests, as they use /etc/fstab, which is *nix/Cygwin only, which will cause the tests to throw an exception as /etc/fstab could not be found.  The proposed patch looks for the Wordpad executable (c:/Windows/write.exe) on Windows as it is a standard part of it, and /etc/fstab otherwise.  The tests will therefore pass on Windows builds...
Comment 2 Fan, Chun-wei 2014-09-17 05:15:02 UTC
Created attachment 286338 [details] [review]
Fix build of glibmm_ustring_compose on Visual Studio

Hi,

Later Visual Studio versions are quite picky regarding type casting, so we need to do some casting to the string so that the test will build and run.

These are what I have for now.

With blessings, thank you!
Comment 3 Murray Cumming 2014-09-17 07:56:15 UTC
Review of attachment 286337 [details] [review]:

Looks good. Please push.
Comment 4 Murray Cumming 2014-09-17 07:56:55 UTC
Review of attachment 286338 [details] [review]:

Isn't there some way to make this work without the need for the strange cast?
Comment 5 Fan, Chun-wei 2014-09-17 11:32:55 UTC
Created attachment 286359 [details] [review]
Fix build of glibmm_ustring_compose on Visual Studio (take ii)

Hello Murray,

Thanks for the review, attachment 286337 [details] [review] was pushed as d95bc556.

This is the revised patch for glibmm_ustring_compose.

With blessings, thank you!
Comment 6 Kjell Ahlstedt 2014-09-18 09:19:50 UTC
With the patch in comment 5 Glib::ustring::compose() is not called with
a string literal. The test does not test what it intends to test.
If it's not possible to call compose() with a string literal, I suppose either
compose() should be fixed, or if that's not possible, a note need to be added
to its description.

Why doesn't Visual Studio accept the call with a string literal? Does it
print an understandable error message?
Comment 7 Fan, Chun-wei 2014-09-18 11:04:17 UTC
Hello Kjell,

This is what I get, oddly:

c:\gnome.build.unstable\vs10\Win32\include\glibmm-2.4\glibmm/ustring.h(1340) : e
rror C2668: 'Glib::ustring::Stringify<T>::Stringify' : ambiguous call to overloa
ded function
        with
        [
            T=const char [15]
        ]
        c:\gnome.build.unstable\vs10\Win32\include\glibmm-2.4\glibmm/ustring.h(1
272): could be 'Glib::ustring::Stringify<T>::Stringify(const char *)'
        with
        [
            T=const char [15]
        ]
        c:\gnome.build.unstable\vs10\Win32\include\glibmm-2.4\glibmm/ustring.h(1
269): or       'Glib::ustring::Stringify<T>::Stringify(T (&))'
        with
        [
            T=const char [15]
        ]
        while trying to match the argument list '(const char [15])'
        main.cc(18) : see reference to function template instantiation 'Glib::us
tring Glib::ustring::compose<const char[15]>(const Glib::ustring &,T1 (&))' bein
g compiled
        with
        [
            T1=const char [15]
        ]
c:\gnome.build.unstable\vs10\Win32\include\glibmm-2.4\glibmm/ustring.h(1351) : e
rror C2668: 'Glib::ustring::Stringify<T>::Stringify' : ambiguous call to overloa
ded function
        with
        [
            T=const char [15]
        ]
        c:\gnome.build.unstable\vs10\Win32\include\glibmm-2.4\glibmm/ustring.h(1
272): could be 'Glib::ustring::Stringify<T>::Stringify(const char *)'
        with
        [
            T=const char [15]
        ]
        c:\gnome.build.unstable\vs10\Win32\include\glibmm-2.4\glibmm/ustring.h(1
269): or       'Glib::ustring::Stringify<T>::Stringify(T (&))'
        with
        [
            T=const char [15]
        ]
        while trying to match the argument list '(const char [15])'
        main.cc(19) : see reference to function template instantiation 'Glib::us
tring Glib::ustring::compose<const char*,const char[15]>(const Glib::ustring &,c
onst T1 &,T2 (&))' being compiled
        with
        [
            T1=const char *,
            T2=const char [15]
        ]
Comment 8 Fan, Chun-wei 2014-09-19 05:55:31 UTC
Created attachment 286568 [details] [review]
ustring.h: Add specialization for string literals in the form of const char[N]

Hi,

This patch attempts to fix the part using string literals where they are taken as const char[N] by compilers, such as under Visual Studio.

With blessings, thank you!
Comment 9 Kjell Ahlstedt 2014-09-19 07:26:28 UTC
Glib::ustring::Stringify has a rather strange set of specializations.
There are specializations for Glib::ustring, const char* and char[],
but there are no specializations for const Glib::ustring, char*,
const char[], std::string or const std::string.

I added calls to Glib::ustring::compose() with all of these:
  char arr[] = "array";
  const char carr[] = "const array";
  char* parr = arr;
  const char* pcarr = carr;
  Glib::ustring ustr = "ustring";
  const Glib::ustring custr = "const ustring";
  std::string str = "std::string";
  const std::string cstr = "const std::string";

g++ accepted all the calls. It did not report any ambiguous calls.
Strange, actually!

I also tested your patch. It does not cause any problems when compiling with
g++. 'make' and 'make check' still work. If the patch solves a problem for
Visual Studio, I recommend that you push it.
Comment 10 Fan, Chun-wei 2014-09-19 07:41:31 UTC
Hello Kjell,

I agree that it's odd in this sense, but anyways, thanks for the reviews and patience though.

I have pushed attachment 286568 [details] [review] as 169cce1e.

Will close this bug now, as this bug is a Visual Studio-related build issue.

With blessings, thank you!
Comment 11 Murray Cumming 2014-09-19 17:30:31 UTC
Review of attachment 286568 [details] [review]:

::: glib/glibmm/ustring.h
@@ +1328,3 @@
 
+/** A template specialization for Stringify<const char[N]> (for string literals),
+ * because the regular template has ambiguous constructor overloads for char*.

Please mention that it's ambiguous only on MSVC++.
Comment 12 Fan, Chun-wei 2014-09-20 12:21:21 UTC
Hello Murray,

(In reply to comment #11)
>...
> Please mention that it's ambiguous only on MSVC++.

Just did that in commit b2599d49, thanks for the reminder.

With blessings, thank you!