Opened 12 years ago

Closed 9 years ago

#5141 closed Bugs (wontfix)

class template 'value' (bind.hpp) can corrupt compilability of sound code

Reported by: Joachim Faulhaber Owned by: Peter Dimov
Milestone: To Be Determined Component: bind
Version: Boost 1.46.0 Severity: Problem
Keywords: unexpected compilation dependencies Cc:

Description

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.

Attachments (1)

boost_bind_bind_hpp.patch (8.7 KB ) - added by Joachim Faulhaber 12 years ago.
Patch of bost/bind/bind.hpp replacing template class value by _value

Download all attachments as: .zip

Change History (2)

by Joachim Faulhaber, 12 years ago

Attachment: boost_bind_bind_hpp.patch added

Patch of bost/bind/bind.hpp replacing template class value by _value

comment:1 by Peter Dimov, 9 years ago

Resolution: wontfix
Status: newclosed

Closing as wontfix as too old. Please reopen if still relevant.

Note: See TracTickets for help on using tickets.