I'm looking at some codes which makes heavy uses of templates. It compiles fine on GCC, but not on VS (tested on 2003 - 2010 beta 1), where it fails during syntax analysis. Unfortunately I don't know enough of the code structure to be able reduce the problem and reproduce it in only a few lines, so I can only guess at the cause. I'm hoping someone here can point me in the right direction.
We have
template< class UInt, typename IntT,
bool is_signed = std::numeric_limits<IntT>::is_signed >
struct uii_ops_impl;
// ....
template<class UInt>
struct uii_ops_impl< UInt,
typename make_signed<typename UInt::digit_type>::type, true >
{
typedef UInt unbounded_int_type;
typedef typename make_signed< typename unbounded_int_type::digit_type >::type
integral_type;
// ...
static void add(unbounded_int_type& lhs, integral_type rhs);
// ...
};
template<class UInt>
void uii_ops_impl<
UInt, typename make_signed<typename UInt::digit_type>::type,
true >::add(unbounded_int_type& lhs, integral_type rhs)
{
// ....
}
When compiled on VS, the first error message (among many) it returns is
: error C2065: '
unbounded_int_type
' : undeclared identifier
I mean, point at the typedef huh? :-S
EDIT:
It seems there's something to do with
typename make_signed<typename UInt::digit_type>::type
being used as a template parameter. Throughout the rest of the codes, similar typedefs being used in the member function parameter compiles fine. The only difference I can see so far is that none of the other cases have the above line as a template parameter. make_signed
is from Boost.TypeTraits.
EDIT:
Okay, maybe that's not it, because the exact same thing is done in another file where it compiled fine. Hmm...
Bounty EDIT:
Okay, I think it's obvious at this point the problem is not actually where the compiler is complaining about. Only the two member functions definition at that particular point fail. It turns out that explicitly qualifying the parameter still doesn't compile. The only immediate solution is to define the function inline. That passes syntax analysis. However, when trying to instalize the template VS now fails because std::allocator<void>
doesn't have a size_type
member. Turns out VS have a specialization of std::allocator<T>
for T=void that does not declare a size_type
. I thought size_type
is a required member of all allocators?
So the question now is, what could possibly foul up VS so much during syntax analysis that it complains about completely unrelated non-problem as errors, and how do you debug such codes?
p.s. For those that have too much time to spare, the code I'm trying to make work in VS is Kevin Sopp's mp_math in Boost's sandbox, which is based on libtommath.