Opened 15 years ago

Closed 15 years ago

#963 closed Support Requests (wontfix)

typeof: nested types of BOOST_TYPEOF'ed type don't work on gcc 3.4.5 in native mode

Reported by: snaury@… Owned by: Peder Holt
Milestone: Component: None
Version: Boost 1.34.0 Severity: Problem
Keywords: nested typeof gcc Cc:

Description

Example:

#include <boost/typeof/typeof.hpp>
#include <boost/typeof/std/vector.hpp>
BOOST_TYPEOF_REGISTER_TYPE(std::vector<int>::iterator)
BOOST_TYPEOF_REGISTER_TYPE(std::vector<int>::const_iterator)

int main(int argc, char** argv)
{
    std::vector<int> v;
    BOOST_TYPEOF(v)::iterator i = v.begin();
    return 0;
}

Results in an error on gcc-3.4.5

1.cpp:9: error: expected initializer before "i"

This is because apparently you can't do typeof(v)::type in gcc 3.4.5. Workaround is very simple, but maybe it's better if this is implemented in boost.typeof itself:

#include <boost/typeof/typeof.hpp>
#include <boost/typeof/std/vector.hpp>
BOOST_TYPEOF_REGISTER_TYPE(std::vector<int>::iterator)
BOOST_TYPEOF_REGISTER_TYPE(std::vector<int>::const_iterator)

template<typename T> struct ut_type_mirror { typedef T type; };
#define UT_TYPEOF(v) ut_type_mirror<BOOST_TYPEOF(v)>::type

int main(int argc, char** argv)
{
    std::vector<int> v;
    UT_TYPEOF(v)::iterator i = v.begin();
    return 0;
}

Change History (2)

comment:1 by Peder Holt, 15 years ago

Owner: set to Peder Holt
Severity: Showstopper

comment:2 by Peder Holt, 15 years ago

Resolution: wontfix
Severity: ShowstopperProblem
Status: newclosed

The above solution was tested and rejected for the following reason: GCC 3.3.3 (which we probably want to support) ICEs if __typeof__ is wrapped into anything while inside a template:

typedef mpl::identity<__typeof__(1 + 0.5)>::type type; // OK

template<class T> class A
{
   typedef __typeof__(1 + 0.5) type; // OK
   typedef mpl::identity<__typeof__(1 + 0.5)>::type type; // ICE
};

Note: See TracTickets for help on using tickets.