This is the mail archive of the
mailing list for the GCC project.
Re: [cxx-conversion] Support garbage-collected C++ templates
On Wed, Aug 8, 2012 at 3:37 PM, Diego Novillo <email@example.com> wrote:
> On 12-08-08 16:12 , Gabriel Dos Reis wrote:
>> hi Diego,
>> just a word on style in the documentation:
>>> +template<typename T>
>>> +void gt_pch_nx (TP<T> *tp)
>>> + extern void gt_pch_nx (T&);
>>> + /* This marks field 'fld' of type 'T'. */
>>> + gt_pch_nx (tp->fld);
>> 'extern' declaration at local scope if considered an extremely
>> poor style in C++. Furthermore, it does not interact
>> well with template instantiations and scope rules; plus
>> it does not work well when the function actually has an
>> internal linkage.
>> A proper way to bring a symbol into local scope is through
>> a using-declaration:
>> using ::gt_pch_nx;
> I struggled a bit with this. I need to tell the template function that there
> exists a free function gt_pch_nx that takes a T&. This is not something that
> any header file has at the point of this declaration.
> The function gt_pch_nx(T&) is declared and defined later in one of the
> gt-*.h files. This is another problem with the way that gengtype works
> The using-declaration that you propose does not seem to give me what I want,
> though. How does it know that the function takes a T&?
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
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'. */
Am I understanding you correctly?