@@ -15,7 +15,7 @@ public class Decl : Cursor
15
15
private readonly Lazy < Stmt ? > _body ;
16
16
private readonly Lazy < Decl > _canonicalDecl ;
17
17
private readonly Lazy < IReadOnlyList < Decl > > _decls ;
18
- private readonly Lazy < TemplateDecl > _describedTemplate ;
18
+ private readonly Lazy < TemplateDecl ? > _describedTemplate ;
19
19
private readonly Lazy < Decl > _mostRecentDecl ;
20
20
private readonly Lazy < Decl > _nextDeclInContext ;
21
21
private readonly Lazy < Decl > _nonClosureContext ;
@@ -62,7 +62,11 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl
62
62
return decls ;
63
63
} ) ;
64
64
;
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
+ } ) ;
66
70
_mostRecentDecl = new Lazy < Decl > ( ( ) => TranslationUnit . GetOrCreate < Decl > ( Handle . MostRecentDecl ) ) ;
67
71
_nextDeclInContext = new Lazy < Decl > ( ( ) => TranslationUnit . GetOrCreate < Decl > ( Handle . NextDeclInContext ) ) ;
68
72
_nonClosureContext = new Lazy < Decl > ( ( ) => TranslationUnit . GetOrCreate < Decl > ( Handle . NonClosureContext ) ) ;
@@ -90,7 +94,11 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl
90
94
91
95
public IReadOnlyList < Decl > Decls => _decls . Value ;
92
96
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 ;
94
102
95
103
public bool HasAttrs => Handle . HasAttrs ;
96
104
0 commit comments