[typeof] -- BOOST_TYPEOF(*this) ...

Hi all, I wrote a little macro that uses BOOST_TYPEOF to determine the type of one of its arguments, but it fails when I pass (*this) as an argument in vc8. I forced emulation because, according to the docs, vc8 does not seem to have the bug that let other vc compilers actually support native typeof. I don't know the internals of the TYPEOF library well enough to diagnose the problem, but the error is easy to produce. #define BOOST_TYPEOF_COMPLIANT #include <boost/typeof/typeof.hpp> #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() template<class Inner> struct A; BOOST_TYPEOF_REGISTER_TEMPLATE(A,1); #define USES_TYPEOF_IN_A_MACRO(X) \ { \ BOOST_TYPEOF_TPL(X) &ref = X; \ BOOST_TYPEOF_TPL(X)::inner_t inner = X.inner(); \ } template<class Inner> struct A{ typedef Inner inner_t; inner_t inner() { return Inner(); } void do_something() { A<Inner>& star_this = *this; USES_TYPEOF_IN_A_MACRO(star_this); USES_TYPEOF_IN_A_MACRO(*this); //ERROR! } }; void main(){ A<int> a; a.do_something(); }; If there is any way to accomplish the type of access I am attempting from inside a macro I would really appreciate it (in my use case macros seem to be absolutely necessary for other reasons). As you can see from the example it is possible to avoid the problem by creating a reference to *this and passing that, but I do not like this in principle because too many caveats make the macro difficult to use. John

From: "John Femiani" <JOHN.FEMIANI@asu.edu>
I wrote a little macro that uses BOOST_TYPEOF to determine the type of one of its arguments, but it fails when I pass (*this) as an argument in vc8. I forced emulation because, according to the docs, vc8 does not seem to have the bug that let other vc compilers actually support native typeof. I don't know the internals of the TYPEOF library well enough to diagnose the problem, but the error is easy to produce. [...] If there is any way to accomplish the type of access I am attempting from inside a macro I would really appreciate it (in my use case macros seem to be absolutely necessary for other reasons). As you can see from the example it is possible to avoid the problem by creating a reference to *this and passing that, but I do not like this in principle because too many caveats make the macro difficult to use.
I think this problem is not related to the usage inside a macro. It looks like MSVC can't handle "this" inside BOOST_TYPEOF() in general :-( At some point the compiler gets confused, and thinks that "this" is used outside a member function... The "native" usage for vc8 is available in CVS, but unfortunately it will not help with this issue. Regards, Arkadiy

2007/5/14, Vertleyb <vertleyb@hotmail.com>:
From: "John Femiani" <JOHN.FEMIANI@asu.edu>
I wrote a little macro that uses BOOST_TYPEOF to determine the type of one of its arguments, but it fails when I pass (*this) as an argument in vc8. I forced emulation because, according to the docs, vc8 does not seem to have the bug that let other vc compilers actually support native typeof. I don't know the internals of the TYPEOF library well enough to diagnose the problem, but the error is easy to produce. [...] If there is any way to accomplish the type of access I am attempting from inside a macro I would really appreciate it (in my use case macros seem to be absolutely necessary for other reasons). As you can see from the example it is possible to avoid the problem by creating a reference to *this and passing that, but I do not like this in principle because too many caveats make the macro difficult to use.
I think this problem is not related to the usage inside a macro. It looks like MSVC can't handle "this" inside BOOST_TYPEOF() in general :-( At some point the compiler gets confused, and thinks that "this" is used outside a member function...
The "native" usage for vc8 is available in CVS, but unfortunately it will not help with this issue.
The following simple code replicates the problem on VC8.0 template<int a> struct sizer { }; class test { public: void tester() { sizer<sizeof(*this)> a; } }; void main() { } By modifying BOOST_TYPEOF_NESTED_TYPEDEF to eliminate local class templates, I was able to handle "this" inside BOOST_TYPEOF_NESTED_TYPEDEF on this compiler. This fix is trivial, but the problem is that a similar fix for the emulation version of BOOST_TYPEOF_NESTED_TYPEDEF would reimpose the strict limitation that the complexity of the encoded type can not increase BOOST_TYPEOF_LIMIT_SIZE... Regards, Peder
Regards, Arkadiy
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (3)
-
John Femiani
-
Peder Holt
-
Vertleyb