Boost logo

Boost :

Subject: [boost] [bind] class template 'value' can corrupt compilability of sound code: Ticket #5141
From: Joachim Faulhaber (afojgo_at_[hidden])
Date: 2011-01-29 18:04:01


Hi Peter, list,

two days ago I encountered the following situation

For a new project I combined some code like:
#include <boost/my_lib/my_robust_portable_code.hpp>

with some other code
#include <boost/malicious/side_effect_code.hpp>
#include <boost/my_lib/my_robust_portable_code.hpp>

with the effect, that 'my_robust_portable_code.hpp' did not compile
anymore. Although I found a fix, applicable to
'my_robust_portable_code.hpp', I think that such a
<boost/malicious/side_effect_code.hpp> should generally not be
acceptable for independent components of boost.

In the concrete case <boost/tread.hpp> has this malicious potential to
confuse msvc-[8..10] when it preceded some of my boost/icl code.
<boost/tread.hpp> has the potential to break the code of any other
boost library and any user code, if those accidentally use certain
legal expressions. As the example below shows the corrupted code is
not extremely nuts and might occur else were.

Fortunately I was able to locate the problem:

It's at boost/bind/bind.hpp(112):
namespace _bi{
...
template<class T> class value { ... };
...
} //namespace _bi

This is a minimal program to demonstrate how 'class value' can confuse msvc:
//=========================================================
#include <boost/config.hpp>
//--- from boost/bind/bind.hpp(112)
namespace _bi{
    template<class T> class value{};
}

//--- affected code ---------------------------------------
template <class Type> struct some_attribute
{
    BOOST_STATIC_CONSTANT(int, value = 0);
};

template <class Type> struct some_predicate
{
    BOOST_STATIC_CONSTANT(bool,
        value = ( some_attribute<Type>::value < 0)
                //error C2059: syntax error : ')'
                //IF class template value defined before
        );
};
//=========================================================

Although I frankly don't know, how exactly msvc is derailed, it seems
to have problems with 'value' in

some_attribute<Type>::value < 0

a construction that is extremely frequent due to meta programming
conventions introduced by Dave's and Aleksey's boost::mpl. So for a
fix I tried to rename 'class value' by something else like 'class
_value'. Fortunately this is possible, because the class template is a
local implementation object used in boost/bind/bind.hpp only.

After renaming, I successfully ran all tests from boost/bind. Find the
patch file attached. I have also filed a ticket
https://svn.boost.org/trac/boost/ticket/5141

Best regards,
Joachim

-- 
Interval Container Library [Boost.Icl]
http://www.joachim-faulhaber.de



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