Skip to content

Commit 75466ce

Browse files
author
Kjell Ahlstedt
committed
Temporarily undefine the nil macro, if it's defined
* build/cxx.m4: Add SIGC_CXX_PRAGMA_PUSH_POP_MACRO. * configure.ac: Call SIGC_CXX_PRAGMA_PUSH_POP_MACRO. * sigc++config.h.in: Add SIGC_PRAGMA_PUSH_POP_MACRO. * sigc++/functors/macros/functor_trait.h.m4: * sigc++/adaptors/macros/bind.h.m4: * sigc++/adaptors/macros/retype.h.m4: * sigc++/functors/macros/slot.h.m4: * sigc++/macros/signal.h.m4: If nil and SIGC_PRAGMA_PUSH_POP_MACRO are defined, undefine nil temporarily in the header files. nil is a keyword in Objective-C++ and in Mac OS X C++. Bug #695235.
1 parent 9bd7f99 commit 75466ce

File tree

8 files changed

+120
-0
lines changed

8 files changed

+120
-0
lines changed

build/cxx.m4

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,55 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
117117
])
118118
AC_MSG_RESULT([$sigcm_cxx_self_reference_in_member_initialization])
119119
])
120+
121+
dnl
122+
dnl SIGC_CXX_PRAGMA_PUSH_POP_MACRO
123+
dnl
124+
dnl TODO: When we can break ABI, delete this. It's used when nil is
125+
dnl temporarily undefined. See comment in functor_trait.h.
126+
dnl
127+
AC_DEFUN([SIGC_CXX_PRAGMA_PUSH_POP_MACRO],[
128+
AC_MSG_CHECKING([if C++ preprocessor supports pragma push_macro() and pop_macro().])
129+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
130+
[[
131+
#define BEGIN {
132+
#define END }
133+
#pragma push_macro("BEGIN")
134+
#pragma push_macro("END")
135+
#undef BEGIN
136+
#undef END
137+
138+
// BEGIN and END are not prepreprocessor macros
139+
struct Test1
140+
{
141+
int BEGIN;
142+
double END;
143+
};
144+
145+
#pragma pop_macro("BEGIN")
146+
#pragma pop_macro("END")
147+
148+
// BEGIN and END are prepreprocessor macros
149+
struct Test2
150+
BEGIN
151+
int i;
152+
double d;
153+
END;
154+
155+
void func1(Test1& x);
156+
void func2(Test2& x);
157+
]],
158+
[[
159+
Test1 test1;
160+
Test2 test2;
161+
func1(test1);
162+
func2(test2);
163+
]])],
164+
[
165+
sigcm_cxx_pragma_push_pop_macro=yes
166+
AC_DEFINE([SIGC_PRAGMA_PUSH_POP_MACRO],[1],[does the C++ preprocessor support pragma push_macro() and pop_macro().])
167+
],[
168+
sigcm_cxx_pragma_push_pop_macro=no
169+
])
170+
AC_MSG_RESULT([$sigcm_cxx_pragma_push_pop_macro])
171+
])

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ AC_LANG([C++])
5353
SIGC_CXX_GCC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
5454
SIGC_CXX_MSVC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
5555
SIGC_CXX_SELF_REFERENCE_IN_MEMBER_INITIALIZATION
56+
SIGC_CXX_PRAGMA_PUSH_POP_MACRO
5657
SIGC_CXX_HAS_NAMESPACE_STD
5758
SIGC_CXX_HAS_SUN_REVERSE_ITERATOR
5859

sigc++/adaptors/macros/bind.h.m4

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ _FIREWALL([ADAPTORS_BIND])
235235
#include <sigc++/adaptors/adaptor_trait.h>
236236
#include <sigc++/adaptors/bound_argument.h>
237237

238+
//TODO: See comment in functor_trait.h.
239+
#if defined(nil) && defined(SIGC_PRAGMA_PUSH_POP_MACRO)
240+
#define SIGC_NIL_HAS_BEEN_PUSHED 1
241+
#pragma push_macro("nil")
242+
#undef nil
243+
#endif
244+
238245
namespace sigc {
239246

240247
#ifndef DOXYGEN_SHOULD_SKIP_THIS
@@ -403,3 +410,8 @@ bind(const T_functor& _A_func, T_bound1 _A_b1)
403410
FOR(1,CALL_SIZE,[[BIND_COUNT(%1)]])dnl
404411

405412
} /* namespace sigc */
413+
414+
#ifdef SIGC_NIL_HAS_BEEN_PUSHED
415+
#undef SIGC_NIL_HAS_BEEN_PUSHED
416+
#pragma pop_macro("nil")
417+
#endif

sigc++/adaptors/macros/retype.h.m4

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ _FIREWALL([ADAPTORS_RETYPE])
8181
#include <sigc++/functors/mem_fun.h>
8282
#include <sigc++/functors/slot.h>
8383

84+
//TODO: See comment in functor_trait.h.
85+
#if defined(nil) && defined(SIGC_PRAGMA_PUSH_POP_MACRO)
86+
#define SIGC_NIL_HAS_BEEN_PUSHED 1
87+
#pragma push_macro("nil")
88+
#undef nil
89+
#endif
90+
8491
namespace sigc {
8592

8693
/** @defgroup retype retype(), retype_return()
@@ -208,3 +215,8 @@ FOR(0,CALL_SIZE,[[RETYPE_MEM_FUNCTOR(%1,[bound_volatile_])]])dnl
208215
FOR(0,CALL_SIZE,[[RETYPE_MEM_FUNCTOR(%1,[bound_const_volatile_])]])dnl
209216

210217
} /* namespace sigc */
218+
219+
#ifdef SIGC_NIL_HAS_BEEN_PUSHED
220+
#undef SIGC_NIL_HAS_BEEN_PUSHED
221+
#pragma pop_macro("nil")
222+
#endif

sigc++/functors/macros/functor_trait.h.m4

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ _FIREWALL([FUNCTORS_FUNCTOR_TRAIT])
5252

5353
namespace sigc {
5454

55+
//TODO: When we can break ABI, replace nil by something else, such as sigc_nil.
56+
// nil is a keyword in Objective C++. When gcc is used for compiling Objective C++
57+
// programs, nil is defined as a preprocessor macro.
58+
// https://bugzilla.gnome.org/show_bug.cgi?id=695235
59+
#if defined(nil) && defined(SIGC_PRAGMA_PUSH_POP_MACRO)
60+
#define SIGC_NIL_HAS_BEEN_PUSHED 1
61+
#pragma push_macro("nil")
62+
#undef nil
63+
#endif
64+
5565
/** nil struct type.
5666
* The nil struct type is used as default template argument in the
5767
* unnumbered sigc::signal and sigc::slot templates.
@@ -65,6 +75,11 @@ struct nil;
6575
struct nil {};
6676
#endif
6777

78+
#ifdef SIGC_NIL_HAS_BEEN_PUSHED
79+
#undef SIGC_NIL_HAS_BEEN_PUSHED
80+
#pragma pop_macro("nil")
81+
#endif
82+
6883
/** @defgroup sigcfunctors Functors
6984
* Functors are copyable types that define operator()().
7085
*

sigc++/functors/macros/slot.h.m4

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,13 @@ _FIREWALL([FUNCTORS_SLOT])
355355
#include <sigc++/adaptors/adaptor_trait.h>
356356
#include <sigc++/functors/slot_base.h>
357357

358+
//TODO: See comment in functor_trait.h.
359+
#if defined(nil) && defined(SIGC_PRAGMA_PUSH_POP_MACRO)
360+
#define SIGC_NIL_HAS_BEEN_PUSHED 1
361+
#pragma push_macro("nil")
362+
#undef nil
363+
#endif
364+
358365
namespace sigc {
359366

360367
namespace internal {
@@ -441,3 +448,8 @@ SLOT(CALL_SIZE,CALL_SIZE)
441448
FOR(0,eval(CALL_SIZE-1),[[SLOT(%1,CALL_SIZE)]])
442449

443450
} /* namespace sigc */
451+
452+
#ifdef SIGC_NIL_HAS_BEEN_PUSHED
453+
#undef SIGC_NIL_HAS_BEEN_PUSHED
454+
#pragma pop_macro("nil")
455+
#endif

sigc++/macros/signal.h.m4

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,13 @@ divert(0)
568568
#include <sigc++/functors/slot.h>
569569
#include <sigc++/functors/mem_fun.h>
570570

571+
//TODO: See comment in functor_trait.h.
572+
#if defined(nil) && defined(SIGC_PRAGMA_PUSH_POP_MACRO)
573+
#define SIGC_NIL_HAS_BEEN_PUSHED 1
574+
#pragma push_macro("nil")
575+
#undef nil
576+
#endif
577+
571578
//SIGC_TYPEDEF_REDEFINE_ALLOWED:
572579
// TODO: This should have its own test, but I can not create one that gives the error instead of just a warning. murrayc.
573580
// I have just used this because there is a correlation between these two problems.
@@ -1155,4 +1162,9 @@ FOR(0,eval(CALL_SIZE-1),[[SIGNAL(%1)]])
11551162

11561163
} /* namespace sigc */
11571164

1165+
#ifdef SIGC_NIL_HAS_BEEN_PUSHED
1166+
#undef SIGC_NIL_HAS_BEEN_PUSHED
1167+
#pragma pop_macro("nil")
1168+
#endif
1169+
11581170
#endif /* _SIGC_SIGNAL_H_ */

sigc++config.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
# define SIGC_MSVC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD 1
4848
# define SIGC_NEW_DELETE_IN_LIBRARY_ONLY 1 /* To keep ABI compatibility */
4949
# define SIGC_HAVE_NAMESPACE_STD 1
50+
# define SIGC_PRAGMA_PUSH_POP_MACRO 1
5051

5152
#if (_MSC_VER < 1900) && !defined (noexcept)
5253
#define _ALLOW_KEYWORD_MACROS 1
@@ -73,6 +74,9 @@
7374
static member field. */
7475
# undef SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION
7576

77+
/* does the C++ preprocessor support pragma push_macro() and pop_macro(). */
78+
# undef SIGC_PRAGMA_PUSH_POP_MACRO
79+
7680
#endif /* !SIGC_MSC */
7781

7882
#ifdef SIGC_HAVE_NAMESPACE_STD

0 commit comments

Comments
 (0)