I had a couple of problems using some of Gecode macros because they cannot all be safely followed by a semicolon. Here is a proposed patch that uses de "do {...} while (0)" pattern to make these macros safe. This is an old trick that is used a great deal in the Linux kernel.
The patch is against Gecode 2.2.0:
=== modified file 'gecode/int/distinct/dom.icc' --- gecode/int/distinct/dom.icc 2008-12-12 09:17:43 +0000 +++ gecode/int/distinct/dom.icc 2008-12-14 18:41:56 +0000 @@ -662,7 +662,7 @@ return TerDom<View>::post(home,x[0],x[1],x[2]); if (x.size() > 3) { // Do bounds propagation to make view-value graph smaller - GECODE_ES_CHECK(prop_bnd<View>(home,x)) + GECODE_ES_CHECK(prop_bnd<View>(home,x)); (void) new (home) Dom<View>(home,x); } return ES_OK; === modified file 'gecode/kernel/macros.icc' --- gecode/kernel/macros.icc 2008-12-12 09:17:43 +0000 +++ gecode/kernel/macros.icc 2008-12-14 18:41:56 +0000 @@ -42,9 +42,10 @@ * or the commit member function of a branching. * \ingroup TaskActor */ -#define GECODE_ME_CHECK(me) \ +#define GECODE_ME_CHECK(me) do { \ if (::Gecode::me_failed(me)) \ - return ::Gecode::ES_FAILED; + return ::Gecode::ES_FAILED; \ + } while (0) /** * \brief Check whether \a me is failed or modified, and forward failure. @@ -53,12 +54,12 @@ * or the commit member function of a branching. * \ingroup TaskActor */ -#define GECODE_ME_CHECK_MODIFIED(modified, me) { \ +#define GECODE_ME_CHECK_MODIFIED(modified, me) do { \ ModEvent __me__ ## __LINE__ = (me); \ if (::Gecode::me_failed(__me__ ## __LINE__)) \ return ::Gecode::ES_FAILED; \ modified |= ::Gecode::me_modified(__me__ ## __LINE__); \ - } + } while (0) /** * \brief Check whether modification event \a me is failed, and fail space \a home. @@ -66,11 +67,11 @@ * To be used inside post functions. * \ingroup TaskActor */ -#define GECODE_ME_FAIL(home,me) \ +#define GECODE_ME_FAIL(home,me) do { \ if (::Gecode::me_failed(me)) { \ (home)->fail(); \ return; \ - } + }} while (0) @@ -80,11 +81,11 @@ * * \ingroup TaskActor */ -#define GECODE_ES_CHECK(es) { \ +#define GECODE_ES_CHECK(es) do { \ ::Gecode::ExecStatus __es__ ## __LINE__ = (es); \ if (__es__ ## __LINE__ < ::Gecode::ES_OK) \ return __es__ ## __LINE__; \ - } + } while (0) /** * \brief Check whether execution status \a es is failed, and fail @@ -92,26 +93,26 @@ * * \ingroup TaskActor */ -#define GECODE_ES_FAIL(home,es) { \ +#define GECODE_ES_FAIL(home,es) do { \ ::Gecode::ExecStatus __es__ ## __LINE__ = (es); \ assert(__es__ ## __LINE__ != ::Gecode::__ES_SUBSUMED); \ if (__es__ ## __LINE__ < ::Gecode::ES_OK) { \ (home)->fail(); return; \ } \ - } + } while (0) /** * \brief Rewrite propagator by executing post function * * \ingroup TaskActor */ -#define GECODE_REWRITE(prop,post) { \ +#define GECODE_REWRITE(prop,post) do { \ Propagator* __p__ ## __LINE__ = (prop); \ size_t __s__ ## __LINE__ = __p__ ## __LINE__->dispose((home)); \ ExecStatus __es__ ## __LINE__ = (post); \ if (__es__ ## __LINE__ != ::Gecode::ES_OK) \ return ::Gecode::ES_FAILED; \ return ES_SUBSUMED(__p__ ## __LINE__,__s__ ## __LINE__); \ -} + } while (0) // STATISTICS: kernel-other
Cheers, --Denys
_______________________________________________ Gecode users mailing list us...@gecode.org https://www.gecode.org/mailman/listinfo/gecode-users