[gecode-users] Compiling Gecode in gcc 3.3 success

Mikael 'Zayenz' Lagerkvist zayenz at kth.se
Tue Nov 8 10:26:18 CET 2005


Hi,

On 11/7/05, Javier Mena <javimena at gmail.com> wrote:
> The problem is that the file int/gcc/graphsup.icc has calls in the style:
>
> vrn->matched<UBC>()
>
> I have changed of all the calls to (that comforms c++ standard):
>
> vrn->template matched<UBC>()
>
> And it works. I have read the book of Stroustrup (The C++ Programming
> Language), but I cannot understand if one should always have to use
> the "template" keyword before that kind of calls. So, I can't
> understand exactly why does the compiler doesn't recognize the call
> sometimes.

Changing the code in this way makes it compile under the gcc
3.3-series, but it is not correct C++ I believe.  Furthermore, the
code does not compile under gcc 3.4 and later with this change.

It took me some time to find the cases where one needs to add
template, and when it is forbidden. The issue is the following.

Consider the code A->M<B>() . The addition of the word template after
the arrow (making it A->template M<B>()) is done to indicate that M is
a template member of A, and that the '<' token following M is the
start of a template-list and not a less-than token.

This needs to be done if A is dependant on a template parameter of the
enclosing scope of the invocation. However, if the enclosing scope is
not a template, the compiler has static knowledge of the type of A,
which includes the fact that the member M of A is a template. Adding
the disambiguator outside a template is disallowed by the C++ standard
(I'm not sure why, but it is).

This is one of the incompatibilities between gcc up to and including
version 3.3, and later versions.

Regards,
Miakel Lagerkvist

--
Mikael 'Zayenz' Lagerkvist, http://www.imit.kth.se/~zayenz/




More information about the gecode-users mailing list