Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Does anyone have a workaround for this gcc4.3 issue?

21 views
Skip to first unread message

hui...@gmail.com

unread,
Dec 15, 2013, 3:57:02 PM12/15/13
to
Code is as follows. It's legal c++ code, however doesn't compile with g++4.3.
Would really appreciate if anyone has a workaround!! Thanks!

-----------------------------------------------

template < typename T > T& obj();

template < typename T, typename=typeof(obj<T>().memfun()) >
struct test {};

template < typename T > test<T> f(int){}

template <typename> char f(...){}

struct X
{
void memfun(int){};
};

int main()
{
f<X>(0);
}

Alf P. Steinbach

unread,
Dec 15, 2013, 4:56:16 PM12/15/13
to
From the information given it's impossible to say what error g++ 4.3
produces.

See the FAQ item titled "How do I post a question about code that
doesn't work correctly?", currently available at (among others) <url:
http://www.parashift.com/c++-faq/posting-code.html), in particular the
three first bullet points.

It's often a good idea to take a look at the FAQ.

- - -

That said, the code isn't quite valid standard C++:

* In standard C++ there is no `typeof`. It's a g++ language extension.
C++11 does have a similar `decltype`.

* A non-void function must not return by the execution passing out of
the end of the function body, this is Undefined Behavior. Probably,
judging from the code, the functions are meant to be used in compile
time TMP machinery, and then just be unimplemented. But still.

Also, Visual C++ 12.0 refuses to accept the
"typename=typeof(obj<T>().memfun()", but as I recall it has a bug in
this area so it doesn't indicate any other problem than portability:
better rewrite if you want this to compile also with Visual C++.

- - -

Btw., what was the problem?

Can you re-post, according to the FAQ guidelines?


Cheers & hth.,

- Alf

hui...@gmail.com

unread,
Dec 15, 2013, 5:18:52 PM12/15/13
to
Thanks Alf for looking at my post. Here is more information.

The problem is that this code compiles with gcc4.8 and above, as i've tested. however, unfortunately i do not currently have other compiler other than gcc4.3 (at work that is), and i hope to find a workaround for gcc4.3.

The non-compile appears to be a gcc4.3 issue (bug maybe?), where a substitution failure, i.e., the instantiation of test<X> when calling f<X>(0), is mistakenly being treated as an error.

As for the code itself, since i'm using gcc4.3 which doesn't have c++11, therefore no decltype, so i had to use the gcc extension typeof, which is really the only thing non-standard about it.

Thanks.

hui...@gmail.com

unread,
Dec 15, 2013, 5:26:52 PM12/15/13
to
reposted.
0 new messages