Boost logo

Boost :

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


2011/1/30 Jeffrey Lee Hellrung, Jr. <jhellrung_at_[hidden]>:
> On 1/29/2011 3:04 PM, Joachim Faulhaber wrote:
>>
>> Hi Peter, list,
>
> [...]
>>
>> 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
>
> Does adding parentheses, i.e.,
>           value = ( (some_attribute<Type>::value) < 0 )
> help?  If so, it could be an alternative to renaming the "value"
> template...although it could require quite a few more changes to boost
> code...

Yes, it does. That's the remedy I applied for "the affected code". But
obviously it's much better to heal the "malicious code". Fixing the
malicious code is a remedy for all the potential code by users that
could suffer from the effect.

>
>>         );
>> };
>> //=========================================================
>>
>> Although I frankly don't know, how exactly msvc is derailed, it seems
>> to have problems with 'value' in
>>
>> some_attribute<Type>::value<  0
>
> ...worth filing a bug in the MS Connect database?

... no experience with that here :-/

>> 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.
>
> Not sure how many value struct templates there are under boost, but I
> wouldn't be surprised if there were another one for which renaming were
> *not* an option...

Unfortunately you may be right. I did a grep for

class value

and was happy to find only the *one* in boost bind. But for

struct value

we have 11 occurrences in boost.

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