@@ -15,7 +15,7 @@ public class Decl : Cursor
1515 private readonly Lazy < Stmt ? > _body ;
1616 private readonly Lazy < Decl > _canonicalDecl ;
1717 private readonly Lazy < IReadOnlyList < Decl > > _decls ;
18- private readonly Lazy < TemplateDecl > _describedTemplate ;
18+ private readonly Lazy < TemplateDecl ? > _describedTemplate ;
1919 private readonly Lazy < Decl > _mostRecentDecl ;
2020 private readonly Lazy < Decl > _nextDeclInContext ;
2121 private readonly Lazy < Decl > _nonClosureContext ;
@@ -62,7 +62,11 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl
6262 return decls ;
6363 } ) ;
6464;
65- _describedTemplate = new Lazy < TemplateDecl > ( ( ) => TranslationUnit . GetOrCreate < TemplateDecl > ( Handle . DescribedTemplate ) ) ;
65+ _describedTemplate = new Lazy < TemplateDecl ? > ( ( ) =>
66+ {
67+ CXCursor describedTemplate = Handle . DescribedTemplate ;
68+ return describedTemplate . IsNull ? null : TranslationUnit . GetOrCreate < TemplateDecl > ( describedTemplate ) ;
69+ } ) ;
6670 _mostRecentDecl = new Lazy < Decl > ( ( ) => TranslationUnit . GetOrCreate < Decl > ( Handle . MostRecentDecl ) ) ;
6771 _nextDeclInContext = new Lazy < Decl > ( ( ) => TranslationUnit . GetOrCreate < Decl > ( Handle . NextDeclInContext ) ) ;
6872 _nonClosureContext = new Lazy < Decl > ( ( ) => TranslationUnit . GetOrCreate < Decl > ( Handle . NonClosureContext ) ) ;
@@ -90,7 +94,11 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl
9094
9195 public IReadOnlyList < Decl > Decls => _decls . Value ;
9296
93- public TemplateDecl DescribedTemplate => _describedTemplate . Value ;
97+ /// <summary>
98+ /// Per clang documentation: This returns null for partial specializations, because they are not modeled as TemplateDecls.
99+ /// Use DescribedTemplateParams to handle those cases.
100+ /// </summary>
101+ public TemplateDecl ? DescribedTemplate => _describedTemplate . Value ;
94102
95103 public bool HasAttrs => Handle . HasAttrs ;
96104
0 commit comments