diff --git a/sources/ClangSharp/Cursors/Decls/Decl.cs b/sources/ClangSharp/Cursors/Decls/Decl.cs index 15f6401b..741afb59 100644 --- a/sources/ClangSharp/Cursors/Decls/Decl.cs +++ b/sources/ClangSharp/Cursors/Decls/Decl.cs @@ -15,7 +15,7 @@ public class Decl : Cursor private readonly Lazy _body; private readonly Lazy _canonicalDecl; private readonly Lazy> _decls; - private readonly Lazy _describedTemplate; + private readonly Lazy _describedTemplate; private readonly Lazy _mostRecentDecl; private readonly Lazy _nextDeclInContext; private readonly Lazy _nonClosureContext; @@ -62,7 +62,11 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl return decls; }); ; - _describedTemplate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DescribedTemplate)); + _describedTemplate = new Lazy(() => + { + CXCursor describedTemplate = Handle.DescribedTemplate; + return describedTemplate.IsNull ? null : TranslationUnit.GetOrCreate(describedTemplate); + }); _mostRecentDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.MostRecentDecl)); _nextDeclInContext = new Lazy(() => TranslationUnit.GetOrCreate(Handle.NextDeclInContext)); _nonClosureContext = new Lazy(() => TranslationUnit.GetOrCreate(Handle.NonClosureContext)); @@ -90,7 +94,11 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl public IReadOnlyList Decls => _decls.Value; - public TemplateDecl DescribedTemplate => _describedTemplate.Value; + /// + /// Per clang documentation: This returns null for partial specializations, because they are not modeled as TemplateDecls. + /// Use DescribedTemplateParams to handle those cases. + /// + public TemplateDecl? DescribedTemplate => _describedTemplate.Value; public bool HasAttrs => Handle.HasAttrs;