codegraph icon indicating copy to clipboard operation
codegraph copied to clipboard

Support for C++ classes inheriting templated classes in C++

Open ryancu7 opened this issue 5 months ago • 1 comments

CodeGraph is not working very well on our C++ codebase. We have a lot of classes that inherit from templated types. DeepWiki (AI generated) says this could be the reason (more detail). Can CodeGraph support following classes that inherit from templated classes?

ryancu7 avatar Jun 29 '26 01:06 ryancu7

Fixed in #1048 (merged to main).

Root cause: when a class derived from a template — class Derived : public Base<int>, a CRTP base like class App : public CRTPBase<App>, or a struct inheriting a template — CodeGraph recorded the base as the full instantiation text Base<int>. That never matched the template, which is indexed under its bare name Base, so the inheritance edge was dropped and the derived class looked like it inherited from nothing (impact/callers analysis stopped at that boundary).

Fix: the template arguments are now stripped from the base name (Base<int> → Base, ns::Tpl<int> → ns::Tpl), so a templated base resolves exactly like a non-templated one. This covers plain template bases, CRTP, structs, and multi-base clauses, for bases in the same file or same namespace.

One case is still not linked: a base in a different namespace referenced with its qualifier (class Q : public other_ns::Tpl<int>). That's a separate, pre-existing namespace-resolution limitation — the non-templated other_ns::Plain doesn't resolve either — so it's not specific to templates. If that pattern is common in your codebase, open a new issue and we'll track it separately.

This will go out in the next release. Thanks for the report (and the DeepWiki diagnosis — it pointed right at it)!

colbymchenry avatar Jun 29 '26 01:06 colbymchenry