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 734368 - test_lambda.cc not compatible with Microsoft Visual Studio 2013
test_lambda.cc not compatible with Microsoft Visual Studio 2013
Status: RESOLVED FIXED
Product: libsigc++
Classification: Bindings
Component: tests
2.3.x
Other Windows
: Normal minor
: ---
Assigned To: libsigc++ maintainer(s)
libsigc++ maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2014-08-06 16:11 UTC by Ryan Beasley
Modified: 2014-08-12 15:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch: test_lambda: Fix for MS Visual C++ 2013 (2.58 KB, patch)
2014-08-06 18:30 UTC, Kjell Ahlstedt
none Details | Review

Description Ryan Beasley 2014-08-06 16:11:14 UTC
From test_lambda.cc:

  // auto-disconnect
  //
  // The functor returns std::ostream&, but the compiler dislikes both
  // slot<std::ostream>, slot<std::ostream&> and slot<std::ostream*>.
  // std::ostream can be implicitly converted to bool, because it has either
  // operator void*() (before C++11) or operator bool() (since C++11).
  sigc::slot<bool> sl1;
  {
    book guest_book("karl");
    sl1 = (sigc::var(result_stream) << sigc::ref(guest_book) << sigc::var("\n"));
    sl1();
    util->check_result(result_stream, "karl\n");
  } // auto-disconnect
  sl1(); // :-)
  util->check_result(result_stream, "");

basic_ios::operator bool is an explicit conversion operator, so it requires an explicit conversion.  See http://en.cppreference.com/w/cpp/language/explicit and examine the cases of nb1 and nb2 (or Stroustrup §18.4.2).

2>  test_lambda.cc
2>E:\src\git\libsigc++2\sigc++/functors/slot.h(103): error C2440: 'return' : cannot convert from 'std::ostream' to 'bool'
2>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Without thinking about this much (still haven't had my coffee), adding static_cast<T_return>() to slot.h will get rid of the error, but I have no idea what side effects, if any, this may have.

  static T_return call_it(slot_rep* rep)
    {
      typedef typed_slot_rep<T_functor> typed_slot;
      typed_slot *typed_rep = static_cast<typed_slot*>(rep);
      return static_cast<T_return>((typed_rep->functor_)());
    }
Comment 1 Kjell Ahlstedt 2014-08-06 18:30:00 UTC
Created attachment 282728 [details] [review]
patch: test_lambda: Fix for MS Visual C++ 2013

Before you filed this bug, I tested this patch with g++, clang++ and
MSVC++ 2010. No problems.

Can you please test with MS Visual Studio 2013.
sigc::hide_return() does not convert the return type, neither implicitly nor
explicitly. Its function call operator just does not return a value.

I don't want to make any changes in the slot code just because of this test
case, unless necessary. libsigc++'s lambda functions are deprecated.
Comment 2 Kjell Ahlstedt 2014-08-12 13:21:08 UTC
Ryan, can you please test my patch with MS Visual Studio 2013.

Or, if you've got a better patch, test and attach that one.

I don't mean to push you, just want to be sure that you haven't overlooked
my suggested fix. I have no access to MSVS 2013, and I don't plan to buy it.
Comment 3 Ryan Beasley 2014-08-12 14:11:34 UTC
(In reply to comment #2)
> Ryan, can you please test my patch with MS Visual Studio 2013.
> 
> Or, if you've got a better patch, test and attach that one.
> 
> I don't mean to push you, just want to be sure that you haven't overlooked
> my suggested fix. I have no access to MSVS 2013, and I don't plan to buy it.

I'm sorry.  We switched mail systems at work and I haven't yet recreated my filters, so my inbox is overflowing.

Anyway, this patch both a. compiles cleanly and b. succeeds.  Let me know if there's anything else I can run through VS 2013.
Comment 4 Kjell Ahlstedt 2014-08-12 15:17:00 UTC
Thanks!

I have pushed the patch
https://git.gnome.org/browse/libsigc++2/commit/?id=65bcea092fd9a51ff2d9a6374b0f116459190593