Issue 090707.1: Template types appendix
Here's some text that describes the usage of template formals inside
an instance, per 090406.1. And it also describes one case where the
linkage simply doesn't exist.
Appendix D.X: Example uses of template formals inside template instances.
The following example illustrates how information about the nature of
a template parameter replacements happened in an instance of the template.
Consider the C++ source in this example:
template<class T>
struct wrapper {
T comp;
};
wrapper<int> obj;
The DWARF description would be similar to the following:
11$: DW_TAG_structure_type
DW_AT_name("wrapper")
12$: DW_TAG_template_type_parameter
DW_AT_name("T")
DW_AT_type(reference to "int")
13$ DW_TAG_member
DW_AT_name("comp")
DW_AT_type(reference to 12$)
14$: DW_TAG_variable
DW_AT_name("obj")
DW_AT_type(reference to 11$)
The actual type of the component comp is int, but in the DWARF the type
references the DW_TAG_template_type_parameter for "T", which in turn
references "int". This implies that in the original template comp was
of type T and that was replaced with int in the instance.
There exist situations where it is not possible for the DWARF to imply
anything about the nature of the original template. Consider the C++
source in this example:
template<class T>
struct wrapper {
T comp;
};
template<class U>
void consume(wrapper<U> formal)
{
...
}
wrapper<int> obj;
consume(obj);
In this case, the DWARF description would be similar to the following:
11$: DW_TAG_structure_type
DW_AT_name("wrapper")
12$: DW_TAG_template_type_parameter
DW_AT_name("T")
DW_AT_type(reference to "int")
13$ DW_TAG_member
DW_AT_name("comp")
DW_AT_type(reference to 12$)
14$: DW_TAG_variable
DW_AT_name("obj")
DW_AT_type(reference to 11$)
21$: DW_TAG_subprogram
DW_AT_name("consume")
22$: DW_TAG_template_type_parameter
DW_AT_name("U")
DW_AT_type(reference to "int")
23$: DW_TAG_formal_parameter
DW_AT_name("formal")
DW_AT_type(reference to 11$)
In the instance of consume, U is replaced with an "int". But the type
of the formal parameter "formal" is a wrapper<int>. There is no
independent description of wrapper<int> in the instance, because none
is necessary. So it references the type at 11$. That type is aware
that T was replaced with "int", but has no connection to U.
--
August 11, 2009 -- Accepted, with replacement text for the last paragraph
to be provided.