This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [cxx-conversion] Support garbage-collected C++ templates
On Wed, Aug 8, 2012 at 3:58 PM, Diego Novillo <dnovillo@google.com> wrote:
> On Wed, Aug 8, 2012 at 4:47 PM, Gabriel Dos Reis
> <gdr@integrable-solutions.net> wrote:
>
>> So, if the issue that the function does not exist at the point of the template
>> definition, but will definitely exist at the point where it is instantiated
>> because of inclusion of a header file (later or in a different
>> translation unit),
>> then the usual way is to write no declaration at all. The compiler will perform
>> a lookup at the point of instantiation and resolve the name
>> appropriate, or error.
>
>>
>> you can just write:
>>
>> void gt_pch_nx (TP<T> *tp)
>> {
>> /* This marks field 'fld' of type 'T'. */
>> gt_pch_nx (tp->fld);
>>
>> }
>
> Oh, but if I do that I get the error
>
> In file included from tree.h:29:0,
> from cp/tree.c:28:
> vec.h: In instantiation of 'void gt_ggc_mx(vec_t<T>*) [with T = tree_node*]':
> ./gt-cp-tree.h:571:59: required from here
> vec.h:180:5: error: no matching function for call to 'gt_ggc_mx(tree_node*&)'
> gt_ggc_mx (v->vec[i]);
> ^
>
> Because no declaration for gt_ggc_mx(tree_node *) exists at that
> point. It will exist in some other header file that's been generated
> by gengtype (which is included at the *end* of the .c file).
>
Aha, so it is an ordering issue, e.g. declarations being generated
after they have been seen used in an instantiation.
We might want to consider including the header file (that contains
only the declarations of the marking functions) in the header
files that contain the GTY-marked type definition. In this case, it would
be included near the end of tree.h
-- Gaby