Boost logo

Boost :

Subject: [boost] [python] incorrect use of keywords and, or, etc
From: lcaminiti (lorcaminiti_at_[hidden])
Date: 2012-05-25 11:37:45


Hello all,

Boost.Python uses operator keywords in macro expansion. This is a bad idea
because on some compilers like MSVC that implement and, or, etc using macros
#define to &&, ||, these macros will not expand correctly when ciso646 is
included before including python.hpp.

#include <ciso646>

// boost/python/operators.hpp
BOOST_PYTHON_BINARY_OPERATOR(and, rand, &)
BOOST_PYTHON_BINARY_OPERATOR(or, ror, |)
...

This will actually expand to:

BOOST_PYTHON_BINARY_OPERATOR(&&, rand, &)
BOOST_PYTHON_BINARY_OPERATOR(||, ror, |)

And then expand the macro causing a compiler error because the operator code
will have names like op_&&, op_||, etc instead of the intended op_and,
op_or, etc.

An easy and safe fix should be to change the macro to move the _ to the
macro call:

BOOST_PYTHON_BINARY_OPERATOR(_and, rand, &)
BOOST_PYTHON_BINARY_OPERATOR(_or, ror, |)

Now _and, _or, etc are no longer keywords so it's safe to use them.

--Lorenzo

--
View this message in context: http://boost.2283326.n4.nabble.com/boost-python-incorrect-use-of-keywords-and-or-etc-tp4630496.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk