1 #include "testutilities.h"
2 #include <sigc++/sigc++.h>
9 std::ostringstream result_stream;
11 class Param : public sigc::trackable
14 Param(const std::string& name)
19 //so it can only be used with sigc::bind() via std::ref()
20 Param(const Param&) = delete;
21 Param& operator=(const Param&) = delete;
24 Param(Param&&) = delete;
25 Param& operator=(Param&&) = delete;
30 void handler(Param& param)
32 result_stream << " handler(param): param.name_=" << param.name_;
35 } // end anonymous namespace
37 int main(int argc, char* argv[])
39 auto util = TestUtilities::get_instance();
41 if (!util->check_command_args(argc, argv))
42 return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
44 auto slot_full = sigc::ptr_fun(&handler);
45 sigc::slot<void> slot_bound;
48 util->check_result(result_stream, "");
51 //Because Param derives from sigc::trackable(), std::ref() should disconnect
52 // the signal handler when param is destroyed.
53 Param param("murrayc");
54 // A convoluted way to do
55 // slot_bound = sigc::bind(slot_full, std::ref(param));
56 slot_bound = sigc::bind< -1, std::reference_wrapper<Param> >(slot_full, std::ref(param));
58 result_stream << "Calling slot when param exists:";
60 util->check_result(result_stream,
61 "Calling slot when param exists: handler(param): param.name_=murrayc");
64 result_stream << "Calling slot when param does not exist:";
66 util->check_result(result_stream, "Calling slot when param does not exist:");
67 // This causes a crash when using g++ 3.3.4 or 3.3.5 (but not 3.4.x) when not specifying
68 // the exact template specialization in visit_each_type() - see the comments there.
69 // It looks like the auto-disconnect does not work, so the last slot_bound() call tries
70 // to access the param data again.
72 return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;