[typeof]Typeof with MinGW

Hi all. Does Boost.Typeof work with MinGW in a little complex situation? I test it with this: #include <boost/typeof/typeof.hpp> #include <vector> using namespace std; int main() { std::vector<int> v; BOOST_TYPEOF(v)::value_type i; } It failed. But if the line 9 is changed from BOOST_TYPEOF(v)::value_type i; to typedef BOOST_TYPEOF(v) v_type; v_type::value_type i; It works. My question is why BOOST_TYPEOF(v)::value_type is not supported? I'm using MinGW with gcc 4.1.2. (3.4.2 fails too. But vc8 is OK.) Thanks.

2007/5/24, Minmin Gong <gongminmin@yeah.net>:
Hi all. Does Boost.Typeof work with MinGW in a little complex situation? I test it with this:
#include <boost/typeof/typeof.hpp> #include <vector>
using namespace std;
int main() { std::vector<int> v; BOOST_TYPEOF(v)::value_type i; }
It failed. But if the line 9 is changed from BOOST_TYPEOF(v)::value_type i; to typedef BOOST_TYPEOF(v) v_type; v_type::value_type i; It works.
My question is why BOOST_TYPEOF(v)::value_type is not supported? I'm using MinGW with gcc 4.1.2. (3.4.2 fails too. But vc8 is OK.) Thanks.
On GCC we use the native typeof mechanism, so your code is actually translated into this: int main() { std::vector<int> v; typedef typeof(boost::type_of::ensure_obj(v))::type type; } The simpler: typedef typeof(v)::type type; fails to compile as well, so this is a shortcomming in the compiler. Unfortunately there is little we can do to fix this in Boost.Typeof. Regards, Peder
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On 5/24/07, Peder Holt <peder.holt@gmail.com> wrote:
2007/5/24, Minmin Gong <gongminmin@yeah.net>: [...] On GCC we use the native typeof mechanism, so your code is actually translated into this:
int main() { std::vector<int> v; typedef typeof(boost::type_of::ensure_obj(v))::type type; }
The simpler: typedef typeof(v)::type type;
fails to compile as well, so this is a shortcomming in the compiler.
Well, vector has no 'type' type. Anyways, It fail)s for 'iterator' too: std::vector<int> v; typedef typeof(int)::iterator type;
Unfortunately there is little we can do to fix this in Boost.Typeof.
This works though (at least with gcc 4.1.2): #include <vector> template<typename T> struct identity { typedef T type; }; int main() { std::vector<int> v; typedef identity<typeof(v)>::type::iterator type; } So BOOST_TYPEOF could include 'identity' in its expansion. It might fail with more complex expression as I heard that gcc doesn't like much typeof in template parameters (but never tested it). gpd

"Giovanni Piero Deretta" <gpderetta@gmail.com> wrote
This works though (at least with gcc 4.1.2):
#include <vector>
template<typename T> struct identity { typedef T type; };
int main() { std::vector<int> v; typedef identity<typeof(v)>::type::iterator type; }
So BOOST_TYPEOF could include 'identity' in its expansion.
Working around the problem by _complicating_ the expression inside typeof is not a way I would go. It then may fail in another contexts, where it didn't fail before. This is clearly a compiler bug, and needs to be addressed by the compiler developers. Regards, Arkadiy

On 5/24/07, Arkadiy Vertleyb <vertleyb@hotmail.com> wrote:
"Giovanni Piero Deretta" <gpderetta@gmail.com> wrote
This works though (at least with gcc 4.1.2):
#include <vector>
template<typename T> struct identity { typedef T type; };
int main() { std::vector<int> v; typedef identity<typeof(v)>::type::iterator type; }
So BOOST_TYPEOF could include 'identity' in its expansion.
Working around the problem by _complicating_ the expression inside typeof is not a way I would go. It then may fail in another contexts, where it didn't fail before.
Agreed, In fact I said myself that the 'simple' solution could break with more complex expressions.
This is clearly a compiler bug, and needs to be addressed by the compiler developers.
Well, boost as plenty of workarounds for broken compilers, so I do not think this matter much. Even if gcc developers fixthis, older releases will be still broken. Anyways, IIRC next release might support decltype, so the issue is moot. gpd

2007/5/24, Giovanni Piero Deretta <gpderetta@gmail.com>:
On 5/24/07, Peder Holt <peder.holt@gmail.com> wrote:
2007/5/24, Minmin Gong <gongminmin@yeah.net>: [...] On GCC we use the native typeof mechanism, so your code is actually translated into this:
int main() { std::vector<int> v; typedef typeof(boost::type_of::ensure_obj(v))::type type; }
The simpler: typedef typeof(v)::type type;
fails to compile as well, so this is a shortcomming in the compiler.
Well, vector has no 'type' type. Anyways, It fail)s for 'iterator' too:
Sorry. That was a copy and paste error in the mail. My test code used a simpler struct in place of std::vector with a typedef int type;
std::vector<int> v; typedef typeof(int)::iterator type;
Unfortunately there is little we can do to fix this in Boost.Typeof.
This works though (at least with gcc 4.1.2):
#include <vector>
template<typename T> struct identity { typedef T type; };
int main() { std::vector<int> v; typedef identity<typeof(v)>::type::iterator type; }
So BOOST_TYPEOF could include 'identity' in its expansion.
It might fail with more complex expression as I heard that gcc doesn't like much typeof in template parameters (but never tested it).
gpd _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (4)
-
Arkadiy Vertleyb
-
Giovanni Piero Deretta
-
Minmin Gong
-
Peder Holt