[Boost-users] [future] [Visual Studio 8.0] [1.42.0] Include File compiler failure

31 views
Skip to first unread message

Robert Douglas

unread,
Apr 13, 2010, 5:58:16 PM4/13/10
to boost...@lists.boost.org

Using:
Boost 1.42.0
Visual Studio 2.0.50727 SP2

I have a managed C++ project which exposes a set of C++ utilities as a dll. One particular file transitively includes future.hpp. Deep in future.hpp's detail namespace, it comes across:

<code>
struct all_futures_lock
{
unsigned count;
boost::scoped_array<boost::unique_lock<boost::mutex> > locks;

all_futures_lock(std::vector<registered_waiter>& futures):
count(futures.size()),locks(new boost::unique_lock<boost::mutex>[count])
{
for(unsigned i=0;i<count;++i)
{

locks[i]=boost::unique_lock<boost::mutex>(futures[i].future->mutex);
}
}
...
void unlock()
{
for(unsigned i=0;i<count;++i)
{
locks[i].unlock();
}
}
};
</code>

the line :

locks[i].unlock();

fails with the following error:

<a path>\v1_42_0\include\boost/thread/future.hpp(414) : error C2666: 'boost::scoped_array<T>::operator []' : 2 overloads have similar conversions
1> with
1> [
1> T=boost::unique_lock<boost::mutex>
1> ]
1> <a path>\boost\v1_42_0\include\boost/smart_ptr/scoped_array.hpp(77): could be 'boost::unique_lock<Mutex> &boost::scoped_array<T>::operator [](ptrdiff_t) const'
1> with
1> [
1> Mutex=boost::mutex,
1> T=boost::unique_lock<boost::mutex>
1> ]
1> or 'built-in C++ operator[(void (__cdecl *)(boost::scoped_array<T> ***), unsigned int)'
1> with
1> [
1> T=boost::unique_lock<boost::mutex>
1> ]
1> while trying to match the argument list '(boost::scoped_array<T>, unsigned int)'
1> with
1> [
1> T=boost::unique_lock<boost::mutex>
1> ]



Does anyone have any idea what is causing this, and how I might go about resolving it?

Sorry if this has ever been brought up, but I could not find anything about this issue in google searches or this mailing list.

Thanks in Advance!
-RD

Robert Douglas

unread,
Apr 14, 2010, 10:43:15 AM4/14/10
to boost...@lists.boost.org

Sorry to reply to my own post, but I found a solution, though it requires a code change to boost:


struct all_futures_lock
{
      unsigned count;
      boost::scoped_array<boost::unique_lock<boost::mutex> > locks;

      all_futures_lock(std::vector<registered_waiter>& futures):
            count(static_cast<unsigned>(futures.size())),locks(new boost::unique_lock<boost::mutex>[count])

      {
            for(unsigned i=0;i<count;++i)
            {
                  locks[static_cast<std::ptrdiff_t>(i)]=boost::unique_lock<boost::mutex>(futures[i].future->mutex);
            }
      }

      void lock()
      {
            boost::lock(locks.get(),locks.get()+count);

      }

      void unlock()
      {
            for(unsigned i=0;i<count;++i)
            {
                  locks[static_cast<std::ptrdiff_t>(i)].unlock();
            }
      }
};



Note the 3 static casts, the first is to avoid a warning, and the second two are to explicitly convert the unsigned variable to std::ptrdiff_t.

VS 8.0 file "Microsoft Visual Studio 8\VC\include\crtdefs.h" line 516 defines ptrdiff_t as being "_w64 int" type.

Thus, the T& scoped_array<T>::operator[](std::ptrdiff_t i) const function has an argument mismatch with unsigned. I realize that unsigned should convert to int just fine, so I'm not sure if this is a compiler issue or not.

First Question: Is there anyone with a bit more experience on implicit conversions who can shed some light on whether or not the unsigned should be implictly converted to int, or whether a default function should be matched? Other question, is where is this *other* function coming from? Looking through the preprocessed file, I cannot find any other places where there is a operator[] being used on a scoped_array of any type.

Second Question: Is is safe for me to change this header file, and build against it, while linking against the libraries which were built without this change? If not, can anyone suggest a better way to achieve this without having to modify the boost header?

Thanks!
-RD


  
Reply all
Reply to author
Forward
0 new messages