Boost logo

Boost :

Subject: Re: [boost] [python] incorrect use of keywords and, or, etc
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2012-05-25 14:21:46


On Fri, May 25, 2012 at 8:37 AM, lcaminiti <lorcaminiti_at_[hidden]> wrote:

> 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.
>

Sounds like a legitimate issue (as far as working around MSVC
deficiencies); file a trac ticket and attach a patch?

- Jeff


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