I’m trying to use Boost::Interprocess but I have some compiler errors when trying to compile with gcc 4.1.2. I narrowed the code down and managed to reproduce the problem without boost. The code is:
#include <iostream>
static const std::size_t offset_type_alignment = 0;
template<class T, class U>
struct pointer_to_other;
template<class T, class U, template<class> class Sp>
struct pointer_to_other< Sp<T>, U >
/*144*/{
typedef Sp<U> type;
};
template <class PointedType, class DifferenceType, class OffsetType, std::size_t OffsetAlignment>
class offset_ptr
{
};
template <class T, class DifferenceType = std::ptrdiff_t, class OffsetType = std::size_t, std::size_t Alignment = offset_type_alignment>
class offset_ptr;
template<class T, class T2, class T3, std::size_t A, class U>
/*158*/struct pointer_to_other<offset_ptr<T, T2, T3, A>, U >
{
typedef offset_ptr<U, T2, T3, A> type;
};
template<class VoidPointer>
class message_queue_t
{
typedef VoidPointer void_pointer;
/*167*/ typedef typename pointer_to_other<void_pointer, char>::type char_ptr;
};
int main()
{
/*177*/ message_queue_t< offset_ptr<void, std::ptrdiff_t, std::size_t, offset_type_alignment> > test;
}
The errors I get:
.cc: In instantiation of
message_queue_t >.cc:177: instantiated from here
.cc:167: error: ambiguous class template
instantiation for struct pointer_to_other, char>.cc:144: error:
candidates are: struct pointer_to_other, U>.cc:158: error: struct
pointer_to_other, U>.cc:167: error: invalid use of undefined type
âstruct pointer_to_other, char>.cc:140: error: declaration of âstruct
pointer_to_other,
char>â
In MSVS, this compiles fine. Ideone also compiles fine, but it uses gcc 4.3.4.
Important
- changing the compiler is out of the question
- I know Boost::Interprocess wasn’t tested with this version of gcc
What I’m looking for is a workaround. Any ideas?
PS – the templates are part of boost, but reduced, so I can’t really change them. Is there any way I could change:
message_queue_t< offset_ptr<void, std::ptrdiff_t, std::size_t, offset_type_alignment> > test;
in order to make it work?
This is a compiler limitation. It’s simply not supported.