Skip to content

Commit f96dcf1

Browse files
committed
Fix build with -Dbuild-deprecated-api=false
Fixes #82
1 parent 27bcd70 commit f96dcf1

File tree

5 files changed

+51
-10
lines changed

5 files changed

+51
-10
lines changed

examples/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ foreach ex : examples
2020
endforeach
2121

2222
exe_file = executable(ex_name, ex_sources,
23-
cpp_args: '-DSIGCXX_DISABLE_DEPRECATED',
23+
cpp_args: '-DSIGCXX_DISABLE_DEPRECATED=1',
2424
dependencies: sigcxx_own_dep,
2525
implicit_include_directories: false,
2626
build_by_default: build_examples

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pkg_conf_data.set('PACKAGE_VERSION', meson.project_version())
221221
pkg_conf_data.set('SIGCXX_API_VERSION', sigcxx_api_version)
222222

223223
if not build_deprecated_api
224-
pkg_conf_data.set('SIGCXX_DISABLE_DEPRECATED', true)
224+
pkg_conf_data.set('SIGCXX_DISABLE_DEPRECATED', 1)
225225
endif
226226
pkg_conf_data.set('SIGCXX_MAJOR_VERSION', sigcxx_major_version)
227227
pkg_conf_data.set('SIGCXX_MINOR_VERSION', sigcxx_minor_version)

tests/test_cpp11_lambda.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// The only real disadvantage of the C++11 lambda expressions is that a slot that
3333
// contains an object derived from sigc::trackable is not automatically disconnected
3434
// when the object is deleted, if a reference to the object is stored in a C++11
35-
// lambda expression, connected to the slot. But if you use sigc::track_obj(),
35+
// lambda expression, connected to the slot. But if you use sigc::track_object(),
3636
// the slot is automatically disconnected. Thus, the disadvantage is insignificant.
3737
//
3838
// To test the C++11 lambda expressions with gcc 4.6.3 (and probably some later
@@ -265,13 +265,13 @@ int main(int argc, char* argv[])
265265
// Here's an area where the libsigc++ lambda expressions are advantageous.
266266
// If you want to auto-disconnect a slot with a C++11 lambda expression
267267
// that contains references to sigc::trackable-derived objects, you must use
268-
// sigc::track_obj().
268+
// sigc::track_object().
269269
sigc::slot<void, std::ostringstream&> sl1;
270270
{
271271
book guest_book("karl");
272272
//sl1 = (sigc::var(std::cout) << std::ref(guest_book) << sigc::var("\n"));
273273
// sl1 = [&guest_book](std::ostringstream& stream){ stream << guest_book << "\n"; }; // no auto-disconnect
274-
sl1 = sigc::track_obj([&guest_book](std::ostringstream& stream){ stream << guest_book << "\n"; }, guest_book);
274+
sl1 = sigc::track_object([&guest_book](std::ostringstream& stream){ stream << guest_book << "\n"; }, guest_book);
275275
sl1(result_stream);
276276
util->check_result(result_stream, "karl\n");
277277

@@ -323,7 +323,7 @@ int main(int argc, char* argv[])
323323
//sl2 = sigc::group(&egon, std::ref(guest_book));
324324
// sl2 = [&guest_book] () { egon(guest_book); }; // no auto-disconnect
325325
// sl2 = std::bind(&egon, std::ref(guest_book)); // does not compile (gcc 4.6.3)
326-
sl2 = sigc::track_obj([&guest_book] () { egon(guest_book); }, guest_book);
326+
sl2 = sigc::track_object([&guest_book] () { egon(guest_book); }, guest_book);
327327
sl2();
328328
util->check_result(result_stream, "egon(string 'karl')");
329329

@@ -343,7 +343,7 @@ int main(int argc, char* argv[])
343343
// sl2 = std::bind(&egon, std::ref(guest_book)); // does not compile (gcc 4.6.3)
344344
auto fn2 = std::bind(&egon, std::ref(guest_book));
345345
//sl2 = fn2; // no auto-disconnect
346-
sl2 = sigc::track_obj(fn2, guest_book);
346+
sl2 = sigc::track_object(fn2, guest_book);
347347
sl2();
348348
util->check_result(result_stream, "egon(string 'charlie')");
349349

@@ -487,7 +487,7 @@ int main(int argc, char* argv[])
487487
// disconnected automatically if some_bar goes out of scope
488488
//some_signal.connect([&some_bar](){ foo_group4(some_bar); }); // no auto-disconnect
489489
//some_signal.connect(sigc::bind(&foo_group4, std::ref(some_bar))); // auto-disconnects, but we prefer C++11 lambda
490-
some_signal.connect(sigc::track_obj([&some_bar](){ foo_group4(some_bar); }, some_bar));
490+
some_signal.connect(sigc::track_object([&some_bar](){ foo_group4(some_bar); }, some_bar));
491491
some_signal.emit();
492492
util->check_result(result_stream, "foo_group4(bar_group4&)");
493493
}

tests/test_disconnect.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
* Assigned to public domain. Use as you wish without restriction.
33
*/
44

5+
// sigc::signal<>.slots() is deprecated, but let's keep the test if possible.
6+
// If libsigc++ is configured with -Dbuild-deprecated-api=false
7+
// (--disable-deprecated-api), SIGCXX_DISABLE_DEPRECATED is defined in
8+
// sigc++config.h. An undef at the start of this file has no effect.
9+
#undef SIGCXX_DISABLE_DEPRECATED
10+
511
#include "testutilities.h"
612
#include <sigc++/trackable.h>
713
#include <sigc++/signal.h>
@@ -103,11 +109,20 @@ int main(int argc, char* argv[])
103109
util->check_result(result_stream, "sig is connected to foo, bar (size=2): foo(2) bar(2) ");
104110

105111
A a; // iterators stay valid after further connections.
112+
#ifndef SIGCXX_DISABLE_DEPRECATED
106113
cona = sig.slots().insert(conbar, sigc::mem_fun1(a, &A::foo));
114+
#else
115+
cona = sig.connect(sigc::mem_fun1(a, &A::foo));
116+
#endif
107117
result_stream << "sig is connected to foo, A::foo, bar (size=" << sig.size() << "): ";
108118
sig(3);
119+
#ifndef SIGCXX_DISABLE_DEPRECATED
109120
util->check_result(result_stream,
110121
"sig is connected to foo, A::foo, bar (size=3): foo(3) A::foo(3) bar(3) ");
122+
#else
123+
util->check_result(result_stream,
124+
"sig is connected to foo, A::foo, bar (size=3): foo(3) bar(3) A::foo(3) ");
125+
#endif
111126

112127
conbar->disconnect(); // manual disconnection
113128
result_stream << "sig is connected to foo, A::foo (size=" << sig.size() << "): ";

tests/test_track_obj.cc

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
//
2929
// If test_track_obj writes nothing and the return code is 0, the test has passed.
3030

31+
// sigc::track_obj() is deprecated, but let's keep the test if possible.
32+
// If libsigc++ is configured with -Dbuild-deprecated-api=false
33+
// (--disable-deprecated-api), SIGCXX_DISABLE_DEPRECATED is defined in
34+
// sigc++config.h. An undef at the start of this file has no effect.
35+
#undef SIGCXX_DISABLE_DEPRECATED
36+
3137
#include "testutilities.h"
3238
#include <string>
3339
#include <iostream>
@@ -36,7 +42,6 @@
3642
#include <sigc++/adaptors/track_obj.h>
3743
#include <sigc++/signal.h>
3844

39-
4045
namespace
4146
{
4247
std::ostringstream result_stream;
@@ -127,7 +132,11 @@ int main(int argc, char* argv[])
127132
sigc::slot<std::string, int> sl2;
128133
{
129134
bar_group4 bar4;
135+
#ifndef SIGCXX_DISABLE_DEPRECATED
130136
sl1 = sigc::track_obj(Functor1(bar4), bar4);
137+
#else
138+
sl1 = sigc::track_object(Functor1(bar4), bar4);
139+
#endif
131140
sl2 = sigc::track_object(Functor1(bar4), bar4);
132141
result_stream << sl1(-2) << ", " << sl2(2);
133142
util->check_result(result_stream, "negative, positive");
@@ -143,7 +152,11 @@ int main(int argc, char* argv[])
143152
auto psl4 = new sigc::slot<std::string, int, std::string>;
144153
bar_group4* pbar4 = new bar_group4;
145154
book* pbook4 = new book("A Book");
155+
#ifndef SIGCXX_DISABLE_DEPRECATED
146156
*psl3 = sigc::track_obj(Functor2(*pbar4, *pbook4), *pbar4, *pbook4);
157+
#else
158+
*psl3 = sigc::track_object(Functor2(*pbar4, *pbook4), *pbar4, *pbook4);
159+
#endif
147160
*psl4 = sigc::track_object(Functor2(*pbar4, *pbook4), *pbar4, *pbook4);
148161
result_stream << (*psl3)(0, "Book title: ") << ", " << (*psl4)(1, "Title: ");
149162
util->check_result(result_stream, "zero, Book title: A Book, positive, Title: A Book");
@@ -170,8 +183,13 @@ int main(int argc, char* argv[])
170183
{
171184
book guest_book("karl");
172185
// sl1 = [&guest_book](std::ostringstream& stream){ stream << guest_book << "\n"; }; // no auto-disconnect
186+
#ifndef SIGCXX_DISABLE_DEPRECATED
173187
sl11 = sigc::track_obj(
174188
[&guest_book](std::ostringstream& stream) { stream << guest_book; }, guest_book);
189+
#else
190+
sl11 = sigc::track_object(
191+
[&guest_book](std::ostringstream& stream) { stream << guest_book; }, guest_book);
192+
#endif
175193
sl12 = sigc::track_object(
176194
[&guest_book](std::ostringstream& stream) { stream << guest_book; }, guest_book);
177195
sl11(result_stream);
@@ -191,8 +209,12 @@ int main(int argc, char* argv[])
191209
book guest_book("karl");
192210
// sl2 = [&guest_book] () { egon(guest_book); }; // no auto-disconnect
193211
// sl2 = std::bind(&egon, std::ref(guest_book)); // does not compile (gcc 4.6.3)
212+
#ifndef SIGCXX_DISABLE_DEPRECATED
194213
sl21 = sigc::track_obj([&guest_book]() { egon(guest_book); }, guest_book);
195-
sl22 = sigc::track_obj([&guest_book]() { egon(guest_book); }, guest_book);
214+
#else
215+
sl21 = sigc::track_object([&guest_book]() { egon(guest_book); }, guest_book);
216+
#endif
217+
sl22 = sigc::track_object([&guest_book]() { egon(guest_book); }, guest_book);
196218
sl21();
197219
sl22();
198220
util->check_result(result_stream, "egon(string 'karl')egon(string 'egon was here')");
@@ -217,7 +239,11 @@ int main(int argc, char* argv[])
217239
// disconnected automatically if some_bar goes out of scope
218240
//some_signal.connect([&some_bar](){ foo_group4(some_bar); }); // no auto-disconnect
219241
//some_signal.connect(sigc::bind(&foo_group4, std::ref(some_bar))); // auto-disconnects, but we prefer C++11 lambda
242+
#ifndef SIGCXX_DISABLE_DEPRECATED
220243
some_signal.connect(sigc::track_obj([&some_bar](){ foo_group4(some_bar); }, some_bar));
244+
#else
245+
some_signal.connect(sigc::track_object([&some_bar](){ foo_group4(some_bar); }, some_bar));
246+
#endif
221247
some_signal.connect(sigc::track_object([&some_bar](){ foo_group4(some_bar); }, some_bar));
222248
some_signal.emit();
223249
util->check_result(result_stream, "foo_group4(bar_group4&)foo_group4(bar_group4&)");

0 commit comments

Comments
 (0)