[Dwarf-discuss] Extensions for nested template type parameters

Ben Woodard woodard@redhat.com
Tue May 26 15:58:35 GMT 2026


David,

I saw that you looked at this pretty closely in the llvm PR and I am 
probably missing some key detail that you see but I don't see why a 
DWARF extension is needed for this. I tried working it through with pen 
and paper and I didn't run into a problem. The only problem I had was 
that I had trouble keeping the T's straight and so I ended up changing 
it to:

template<typename S> struct t1 { // changed T to S because I'm a simple minded human
   S n1;
};

template<typename T> struct t2 {
   T m1;
   t1<T> m2;
};

int main()
{
   t2<int> v1;
   return 0;
}

The T in m1's declaration is just a normal template instantiation 
referring back to an int.
In m2's declaration refers to its template type parameter which then 
refers to int. However, since it is also a template instantiation the 
type of m2 also referred back to the S template type parameter. So I 
don't see a problem with expressing it in DWARF but rather that 
consumers may have to go through more than one template parameter 
indirection before they get to the actual type of the instantiation.

So what is the crux here that I am missing? What the the DWARF 
enhancement that you are asking for in the LLVM ticket? Right now to me, 
I feel like it should just be an additional example in D.11 and 
consumers need to get smarter.

-ben

On 5/20/26 12:11 AM, Schimpe, Christina via Dwarf-discuss wrote:
> # Extensions for nested template type parameters
>
> Hi all,
>
> In the DWARF 5 Standard (2.23 Template Parameters) it says
> “A debugging information entry that represents a template instantiation
> will contain child entries describing the actual template parameters.
> The containing entry and each of its child entries reference a template
> parameter entry in any circumstance where the template definition
> referenced a formal template parameter.”
>
> I could not find a specification in case a template type parameter is
> passed to another template (nested templates).  Consider the following
> example:
>
> ~~~
> template<typename T> struct t1 {
>    T n1;
> };
>
> template<typename T> struct t2 {
>    T m1;
>    t1<T> m2;
> };
>
> int main()
> {
>    t2<int> v1;
>    return 0;
> }
> ~~~
>
> gcc currently provides the following DWARF for this:
> ~~~
> 0x0000005e:     DW_TAG_member
>                    DW_AT_name    ("m1")
>                    DW_AT_decl_file       ("/tmp/nested_templates.cc")
>                    DW_AT_decl_line       (6)
>                    DW_AT_decl_column     (5)
>                    DW_AT_type    (0x0000004c "int")
>                    DW_AT_data_member_location    (0x00)
>
> 0x00000069:     DW_TAG_member
>                    DW_AT_name    ("m2")
>                    DW_AT_decl_file       ("/tmp/nested_templates.cc")
>                    DW_AT_decl_line       (7)
>                    DW_AT_decl_column     (9)
>                    DW_AT_type    (0x0000002e "t1<int>")
>                    DW_AT_data_member_location    (0x04)
> ~~~
>
> Based on the current specification, the type of m1 should reference
> a template parameter entry.  This is a bug in gcc which has already
> been described [1].  llvm/clang attempted to fix this in PR [2].
>
> Also for m2 we can see that there is no information that its type was
> originally described by a template type parameter of t2.  However,
> there is no specification addressing this specific case in the DWARF
> Standard.
>
> Besides missing consumer support (e.g. GDB or LLDB), missing support for
> nested templates was one further reason why the llvm PR [2] was rejected
> by David Blaikie.  I discussed this topic with him since I am working on
> the enablement in GDB and submitted a patch series [3] to support template
> type resolution based on the current DWARF specification.  David Blaikie
> asked me to submit a DWARF issue for this, since we could not come up with
> a useful specification for the nested case (type of m2 in the example
> above).
>
> So my question is: Can you come up with a useful description of how we
> could extend the DWARF Standard for nested template type parameters?
>
> Kind Regards,
> Christina
>
> ## References
>
> [1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57006
> [2]: https://github.com/llvm/llvm-project/pull/127654
> [3]: https://sourceware.org/pipermail/gdb-patches/2025-December/223619.html
> Intel Deutschland GmbH
> Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
> Tel: +49 89 991 430, www.intel.de
> Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell
> Chairperson of the Supervisory Board: Nicole Lau
> Registered Seat: Munich
> Commercial Register: Amtsgericht Muenchen HRB 186928



More information about the Dwarf-discuss mailing list