Subject: [Boost-bugs] [Boost C++ Libraries] #5141: class template 'value' (bind.hpp) can corrupt compilability of sound code
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-01-29 22:48:44
#5141: class template 'value' (bind.hpp) can corrupt compilability of sound code
-------------------------------------------------+--------------------------
Reporter: jofaber | Owner: pdimov
Type: Bugs | Status: new
Milestone: To Be Determined | Component: bind
Version: Boost 1.46.0 | Severity: Problem
Keywords: unexpected compilation dependencies |
-------------------------------------------------+--------------------------
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` files.
`<boost/tread.hpp>` has the potential to break the code of any other boost
library and any user code. 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.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/5141> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:05 UTC