Issue 090406.1: Template types
BACKGROUND:
In C++ templates, a template type parameter may be referenced within the body of
the template. In an instance of the template, those references are replaced
with the actual types specified in the instantiation. However, there still is
value in having the type references in the DWARF refer to the
DW_TAG_template_type_parameters, so that it's clear that they did so in the
original template. And there is no loss of descriptiveness since each
DW_TAG_template_type_parameter has a DW_AT_type that references the actual type.
My original thoughts on this centered on whether or not a
DW_TAG_template_type_parameter actually qualified as a type. I conclude that
it does. To reiterate on this:
The C++ standard makes pretty clear that a typename (or class) in a template
declaration is considered a type-name within the template itself. This is
analogous to normal type-names for normal type declarations. And the DWARF
standard is clear that a DW_TAG_template_type_parameter represents a "formal
parameterized type declaration" (i.e. typename or class). So to my mind this
means the DWARF standard already implies that a
DW_TAG_template_type_parameter is a type. Of course, this clarity only comes
if you're wearing a language lawyer hat, so I think we could stand to add a
line to really make the point. But given that it's just a clarification
perhaps it can just be italicized text.
But Cary Coutant pointed out that the DWARF standard actually is very precise
about the form of a template instantiation. It says that, with 3 or 4 very
explicit exceptions, it should look exactly like it would look if the
replacement happened manually and there was no template involved at all.
So, if we want type references within the template instance to refer to
DW_TAG_template_type_parameters, we need to make that another explicit
exception. This occurs in two places: 3.3.7 for function template instances,
and 5.6.8 for class template instances.
PROPOSAL:
3.3.7:
In the second paragraph, change "With three exceptions..." to "With four
exceptions..."
Insert numbered item into the list:
2. The subprogram entry and each of its child entries should reference a
template type parameter entry in any circumstance where the template
definition referenced a formal parameterized type.
5.6.8:
In the second paragraph, change "With four exceptions..." to "With five
exceptions..."
Insert numbered item into the list:
3. The class type entry and each of its child entries should reference a
template type parameter entry in any circumstance where the template
definition referenced a formal parameterized type. Similarly, the
class type entry and each of its child entries should reference a
template value parameter entry in any circumstance where the template
definition referenced a formal parameterized value.
--
Revised May 5, 2009: Convert non-normative text to normative changes.
Accepted July 7, 2009