GNOME Bugzilla – Bug 734368
test_lambda.cc not compatible with Microsoft Visual Studio 2013
Last modified: 2014-08-12 15:17:00 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_)()); }
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.
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.
(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.
Thanks! I have pushed the patch https://git.gnome.org/browse/libsigc++2/commit/?id=65bcea092fd9a51ff2d9a6374b0f116459190593