Skip to content

Commit 10dd1c7

Browse files
committed
Fix build with -Dbuild-deprecated-api=false
Fixes #82
1 parent 83422a7 commit 10dd1c7

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
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
@@ -225,7 +225,7 @@ pkg_conf_data.set('PACKAGE_VERSION', meson.project_version())
225225
pkg_conf_data.set('SIGCXX_API_VERSION', sigcxx_api_version)
226226

227227
if not build_deprecated_api
228-
pkg_conf_data.set('SIGCXX_DISABLE_DEPRECATED', true)
228+
pkg_conf_data.set('SIGCXX_DISABLE_DEPRECATED', 1)
229229
endif
230230
pkg_conf_data.set('SIGCXX_MAJOR_VERSION', sigcxx_major_version)
231231
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
@@ -270,14 +270,14 @@ main(int argc, char* argv[])
270270
// Here's an area where the libsigc++ lambda expressions are advantageous.
271271
// If you want to auto-disconnect a slot with a C++11 lambda expression
272272
// that contains references to sigc::trackable-derived objects, you must use
273-
// sigc::track_obj().
273+
// sigc::track_object().
274274
sigc::slot<void(std::ostringstream&)> sl1;
275275
{
276276
book guest_book("karl");
277277
// sl1 = (sigc::var(std::cout) << std::ref(guest_book) << sigc::var("\n"));
278278
// sl1 = [&guest_book](std::ostringstream& stream){ stream << guest_book << "\n"; }; // no
279279
// auto-disconnect
280-
sl1 = sigc::track_obj(
280+
sl1 = sigc::track_object(
281281
[&guest_book](std::ostringstream& stream) { stream << guest_book << "\n"; }, guest_book);
282282
sl1(result_stream);
283283
util->check_result(result_stream, "karl\n");
@@ -332,7 +332,7 @@ main(int argc, char* argv[])
332332
// sl2 = sigc::group(&egon, std::ref(guest_book));
333333
// sl2 = [&guest_book] () { egon(guest_book); }; // no auto-disconnect
334334
// sl2 = std::bind(&egon, std::ref(guest_book)); // does not compile (gcc 4.6.3)
335-
sl2 = sigc::track_obj([&guest_book]() { egon(guest_book); }, guest_book);
335+
sl2 = sigc::track_object([&guest_book]() { egon(guest_book); }, guest_book);
336336
sl2();
337337
util->check_result(result_stream, "egon(string 'karl')");
338338

@@ -352,7 +352,7 @@ main(int argc, char* argv[])
352352
// sl2 = std::bind(&egon, std::ref(guest_book)); // does not compile (gcc 4.6.3)
353353
auto fn2 = std::bind(&egon, std::ref(guest_book));
354354
// sl2 = fn2; // no auto-disconnect
355-
sl2 = sigc::track_obj(fn2, guest_book);
355+
sl2 = sigc::track_object(fn2, guest_book);
356356
sl2();
357357
util->check_result(result_stream, "egon(string 'charlie')");
358358

@@ -502,7 +502,7 @@ main(int argc, char* argv[])
502502
// some_signal.connect([&some_bar](){ foo_group4(some_bar); }); // no auto-disconnect
503503
// some_signal.connect(sigc::bind(&foo_group4, std::ref(some_bar))); // auto-disconnects, but
504504
// we prefer C++11 lambda
505-
some_signal.connect(sigc::track_obj([&some_bar]() { foo_group4(some_bar); }, some_bar));
505+
some_signal.connect(sigc::track_object([&some_bar]() { foo_group4(some_bar); }, some_bar));
506506
some_signal.emit();
507507
util->check_result(result_stream, "foo_group4(bar_group4&)");
508508
}

tests/test_track_obj.cc

Lines changed: 28 additions & 1 deletion
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 <iostream>
3339
#include <sigc++/adaptors/track_obj.h>
@@ -118,7 +124,11 @@ main(int argc, char* argv[])
118124
sigc::slot<std::string(int)> sl2;
119125
{
120126
bar_group4 bar4;
127+
#ifndef SIGCXX_DISABLE_DEPRECATED
121128
sl1 = sigc::track_obj(Functor1(bar4), bar4);
129+
#else
130+
sl1 = sigc::track_object(Functor1(bar4), bar4);
131+
#endif
122132
sl2 = sigc::track_object(Functor1(bar4), bar4);
123133
result_stream << sl1(-2) << ", " << sl2(2);
124134
util->check_result(result_stream, "negative, positive");
@@ -134,7 +144,11 @@ main(int argc, char* argv[])
134144
auto psl4 = new sigc::slot<std::string(int, std::string)>;
135145
auto pbar4 = new bar_group4;
136146
auto pbook4 = new book("A Book");
147+
#ifndef SIGCXX_DISABLE_DEPRECATED
137148
*psl3 = sigc::track_obj(Functor2(*pbar4, *pbook4), *pbar4, *pbook4);
149+
#else
150+
*psl3 = sigc::track_object(Functor2(*pbar4, *pbook4), *pbar4, *pbook4);
151+
#endif
138152
*psl4 = sigc::track_object(Functor2(*pbar4, *pbook4), *pbar4, *pbook4);
139153
result_stream << (*psl3)(0, "Book title: ") << ", " << (*psl4)(1, "Title: ");
140154
util->check_result(result_stream, "zero, Book title: A Book, positive, Title: A Book");
@@ -162,8 +176,13 @@ main(int argc, char* argv[])
162176
book guest_book("karl");
163177
// no auto-disconnect
164178
// sl1 = [&guest_book](std::ostringstream& stream){ stream << guest_book << "\n"; };
179+
#ifndef SIGCXX_DISABLE_DEPRECATED
165180
sl11 = sigc::track_obj(
166181
[&guest_book](std::ostringstream& stream) { stream << guest_book; }, guest_book);
182+
#else
183+
sl11 = sigc::track_object(
184+
[&guest_book](std::ostringstream& stream) { stream << guest_book; }, guest_book);
185+
#endif
167186
sl12 = sigc::track_object(
168187
[&guest_book](std::ostringstream& stream) { stream << guest_book; }, guest_book);
169188
sl11(result_stream);
@@ -183,8 +202,12 @@ main(int argc, char* argv[])
183202
book guest_book("karl");
184203
// sl2 = [&guest_book] () { egon(guest_book); }; // no auto-disconnect
185204
// sl2 = std::bind(&egon, std::ref(guest_book)); // does not compile (gcc 4.6.3)
205+
#ifndef SIGCXX_DISABLE_DEPRECATED
186206
sl21 = sigc::track_obj([&guest_book]() { egon(guest_book); }, guest_book);
187-
sl22 = sigc::track_obj([&guest_book]() { egon(guest_book); }, guest_book);
207+
#else
208+
sl21 = sigc::track_object([&guest_book]() { egon(guest_book); }, guest_book);
209+
#endif
210+
sl22 = sigc::track_object([&guest_book]() { egon(guest_book); }, guest_book);
188211
sl21();
189212
sl22();
190213
util->check_result(result_stream, "egon(string 'karl')egon(string 'egon was here')");
@@ -208,7 +231,11 @@ main(int argc, char* argv[])
208231
// some_signal.connect([&some_bar](){ foo_group4(some_bar); }); // no auto-disconnect
209232
// some_signal.connect(sigc::bind(&foo_group4, std::ref(some_bar))); // auto-disconnects,
210233
// but we prefer C++11 lambda
234+
#ifndef SIGCXX_DISABLE_DEPRECATED
211235
some_signal.connect(sigc::track_obj([&some_bar]() { foo_group4(some_bar); }, some_bar));
236+
#else
237+
some_signal.connect(sigc::track_object([&some_bar]() { foo_group4(some_bar); }, some_bar));
238+
#endif
212239
some_signal.connect(sigc::track_object([&some_bar]() { foo_group4(some_bar); }, some_bar));
213240
some_signal.emit();
214241
util->check_result(result_stream, "foo_group4(bar_group4&)foo_group4(bar_group4&)");

0 commit comments

Comments
 (0)