Boost logo

Boost :

From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2005-05-30 22:35:51


"Alexander Nasonov" <alnsn-boost_at_[hidden]> wrote

> BOOST_TYPEOF( Z() ), where Z is a class type, gives different results in
native
> and compliant modes, at least on gcc 3.2.2.
>
> #include <boost/typeof/typeof.hpp>
> #include <boost/mpl/assert.hpp>
> #include <boost/type_traits/is_same.hpp>
>
> #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
>
> struct Z {};
>
> BOOST_TYPEOF_REGISTER_TYPE(Z)
>
>
> int main()
> {
> typedef Z(F)(); // function in native mode
> typedef BOOST_TYPEOF( Z() ) fn_or_class;
>
> // Which line should be commeneted?
> BOOST_MPL_ASSERT(( boost::is_same<fn_or_class,Z> ));
> BOOST_MPL_ASSERT(( boost::is_same<fn_or_class,F> ));
> }

Well, the meaning of Z() is ambiguous. It can be

1) a default-constructed temporary object of class Z;
2) a type, which is a function that accepts no parameters and returns Z.

A native gcc typeof can handle types, as well as objects: __typeof__(int) is
valid in g++. So the compiler has a choice: either interpret Z() as a type
or an object, and apparently chooses the easier one (I think the right thing
would be to complain about the ambiguity).

In case of emulation the argument of typeof is passed to a function, so it
is unambiguously interpreted as an object.

I don't think we can do much about it except mention in the docs that we
can't handle types in the emulation mode.

Regards,
Arkadiy


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