[Boost-bugs] [Boost C++ Libraries] #2704: range lock algorithm fails with iterators

Subject: [Boost-bugs] [Boost C++ Libraries] #2704: range lock algorithm fails with iterators
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-01-31 16:14:54

#2704: range lock algorithm fails with iterators
 Reporter: jwakely.boost_at_[hidden] | Owner: anthonyw
     Type: Bugs | Status: new
Milestone: Boost 1.38.0 | Component: thread
  Version: Boost 1.37.0 | Severity: Problem
 Keywords: |
 #include <boost/thread.hpp>

 #include <vector>

 int main()
     std::vector<boost::mutex> v;

     // boost::lock(&v.front(), &v.front()+v.size());
     boost::lock(v.begin(), v.end());

     return 0;

 With GCC 4.3.2 and 4.4 this fails to compile, complaining that
 std::vector<mutex>::iterator does not have members lock, unlock and
 try_lock e.g.
 /home/redi/src/boost/boost/thread/locks.hpp: In static member function
 â€˜static char boost::detail::has_member_try_lock<T>::has_member(U*, bool
 (U::*)()) [with U = __gnu_cxx::__normal_iterator<boost::mutex*,
 std::vector<boost::mutex, std::allocator<boost::mutex> > >, T =
 __gnu_cxx::__normal_iterator<boost::mutex*, std::vector<boost::mutex,
 std::allocator<boost::mutex> > >]’:
 /home/redi/src/boost/boost/thread/locks.hpp:75: instantiated from ‘const
 std::vector<boost::mutex, std::allocator<boost::mutex> > > >::value’
 /home/redi/src/boost/boost/thread/locks.hpp:84: instantiated from ‘const
 bool boost::is_mutex_type<__gnu_cxx::__normal_iterator<boost::mutex*,
 std::vector<boost::mutex, std::allocator<boost::mutex> > > >::value’
 /home/redi/src/boost/boost/thread/locks.hpp:1133: instantiated from
 â€˜void boost::lock(const MutexType1&, const MutexType2&) [with MutexType1 =
 __gnu_cxx::__normal_iterator<boost::mutex*, std::vector<boost::mutex,
 std::allocator<boost::mutex> > >, MutexType2 =
 __gnu_cxx::__normal_iterator<boost::mutex*, std::vector<boost::mutex,
 std::allocator<boost::mutex> > >]’
 lock_range.cc:10: instantiated from here

 The commented-out line above compiles fine, using mutex* as the Iterator
 type rather than std::vector<mutex>::iterator.

 I don't think SFINAE applies in has_member_try_lock<T>::has_member<U>,
 because bool(U::*)() is a valid type for iterators classes, so
 substitution succeeds, but &U::try_lock is not a valid expression.

 In the pointer case where U is a pointer, bool(U::*)() is not a valid
 type, so substitution fails, but is not an error.

 The attached patch (against trunk) adds another default argument to
 has_member_{lock,try_lock,unlock}::has_member with a type that depends on
 the presence of a member with the right name. I think this would still
 fail to compile if used with an iterator type that had a member
 lock/try_lock/unlock with a different signature to that expected by the
 Lockable concept.


Ticket URL: <https://svn.boost.org/trac/boost/ticket/2704>
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:49:59 UTC