Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2006-02-06 19:49:18


Hi Arkadiy and Peder et all

I have been testing out replacing my return type deduction scheme in signatures
with typeof. see code and errors at the end.
Unfortunately gcc has major problems with it. compiles fine in VC7.1
Nevertheless I think its an important use case. Looking through the Typeof tests
it doesnt seem to be there.
I shall of course submit a bug report to gnu about it though maybe I'll wait to
the next release assuming it includes Typeof.

I dont suppose theres anything you can do about it, but I thought I'd let you
know anyway.

regards
Andy Little

#include <boost/typeof/typeof.hpp>
#include <iostream>
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()

namespace my{
    template <typename T>
    class udt;
}
BOOST_TYPEOF_REGISTER_TEMPLATE(my::udt,1);
namespace my{

    template <typename T>
    class udt{
        T m_value;
    public:
        T get_value()const{ return m_value;}
        udt():m_value(0){}
        explicit udt(T const & in) : m_value(in){}
        template <typename T1>
        udt<BOOST_TYPEOF_TPL(T(1) + T1(1))>
        operator +( udt<T1> const & in)const
        {
            typedef udt<BOOST_TYPEOF_TPL(T(1) + T1(1))> result_type;
            result_type result(m_value + in.get_value());
            return result;
        }

    };

    template <typename T>
    std::ostream & operator <<(std::ostream& os, udt<T> const & u)
    {
        os << "{" << u.get_value() << "}";
        return os;
    }
}
int main()
{
     my::udt<int> v1(1);
     my::udt<double> v2(2.4);
     std::cout << v1 + v2 << '\n';

}

gcc 4.0.1 error:

test.cpp: In member function 'my::udt<__typeof__
(boost::type_of::ensure_obj(((T)(1) + (T1)(1))))> my::udt<T>::operator+(const
my::udt<T1>&) const [with T1 = double, T = int]':
test.cpp:26: internal compiler error: in write_type, at cp/mangle.c:1646
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

gcc 3.2 error

test.cpp: In instantiation of `my::udt<int>':
test.cpp:40: instantiated from here
test.cpp:23: invalid use of template type parameter
test.cpp:23: confused by earlier errors, bailing out


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk