Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(graph): a template forward declaration is a declaration too (#1703)
Raghav Chamadiyab79134bb52ec
diff --git a/packages/core/src/repowise/core/ingestion/parser.py b/packages/core/src/repowise/core/ingestion/parser.pyindex c835fcf4b..a645920d9 100644--- a/packages/core/src/repowise/core/ingestion/parser.py+++ b/packages/core/src/repowise/core/ingestion/parser.py@@ -138,6 +138,15 @@ def _is_bodiless_cpp_type(language: str, node_type: str, def_node: Node) -> bool"""if language not in ("cpp", "c"):return False+ if node_type == "template_declaration":+ # ``template <typename T> class Foo;``. The wrapper carries no ``body``+ # field of its own — the inner specifier does — so asking the wrapper+ # would call every template a declaration. Ask the type it wraps.+ inner = next(+ (c for c in def_node.children if c.type in _CPP_TYPE_SPECIFIER_NODES),+ None,+ )+ return inner is not None and inner.child_by_field_name("body") is Noneif node_type not in _CPP_TYPE_SPECIFIER_NODES:return Falseif def_node.child_by_field_name("body") is not None:diff --git a/tests/unit/ingestion/test_cpp_decl_def.py b/tests/unit/ingestion/test_cpp_decl_def.pyindex ac42a2b5f..afa395367 100644--- a/tests/unit/ingestion/test_cpp_decl_def.py+++ b/tests/unit/ingestion/test_cpp_decl_def.py@@ -177,3 +177,19 @@ class TestTypeDeclarationFlag:assert graph.get_edge_data("def_first.h", "def_first.h::Shape") == {"edge_type": "defines"}++ def test_bodiless_template_type_is_marked(self, tmp_path: Path) -> None:+ # ``template <typename T> class Foo;`` — the wrapper node carries no+ # ``body`` field of its own, so the check has to ask the type it wraps+ # or every template reads as a declaration.+ (tmp_path / "t.hh").write_text(+ "template <typename T> class Foo;\n"+ "template <typename T> class Bar { int x; };\n"+ "template <typename... T>\nclass Multi;\n"+ "template <typename T> T fn() { return T(); }\n"+ )+ graph = _build(tmp_path)+ assert graph.nodes["t.hh::Foo"]["is_declaration"] is True+ assert graph.nodes["t.hh::Multi"]["is_declaration"] is True+ assert graph.nodes["t.hh::Bar"]["is_declaration"] is False+ assert graph.nodes["t.hh::fn"]["is_declaration"] is False