Summary
A .h file whose only C++ syntax is struct Derived : Base is classified as C. The derived struct is missing from the index, and a phantom function Base with returnType=Derived is emitted at the derived declaration line.
This differs from #1159: the current heuristic handles struct ENGINE_API Derived : Base, but not the plain form without an export macro.
Minimal reproduction
Create src/min.h:
struct Base {};
struct Derived : Base {};
Run:
codegraph init .
codegraph query Derived --json
codegraph query Base --json
Actual:
Derived -> []
Base -> struct Base (language=c, line 1)
function Base (language=c, line 2, returnType=Derived)
Expected: Derived is indexed as a C++ struct, with no phantom function.
Renaming the file to .hpp, adding namespace marker {}, or mapping .h to cpp in codegraph.json makes Derived index correctly. This isolates the problem to .h language detection.
Root cause
looksLikeCpp() checks only the first 8192 characters and does not recognize a plain struct Name : Base clause. The file therefore falls back to the C grammar.
Suggested fix
Recognize class/struct base clauses as a C++ signal and scan the full source for that signal. Adding the pattern only to the existing 8192-character sample would still fail on large headers with a long C-compatible preamble.
Regression tests should cover the plain form, a base clause after character 8192, absence of the phantom function, and a genuine C bitfield control.
Environment
@colbymchenry/codegraph 1.5.0
- Windows x64
- The same heuristic is present on current
main at 81e1f4a92fdbd9413ba73cf72c8a5408102a7897
Summary
A
.hfile whose only C++ syntax isstruct Derived : Baseis classified as C. The derived struct is missing from the index, and a phantomfunction BasewithreturnType=Derivedis emitted at the derived declaration line.This differs from #1159: the current heuristic handles
struct ENGINE_API Derived : Base, but not the plain form without an export macro.Minimal reproduction
Create
src/min.h:Run:
Actual:
Expected:
Derivedis indexed as a C++struct, with no phantom function.Renaming the file to
.hpp, addingnamespace marker {}, or mapping.htocppincodegraph.jsonmakesDerivedindex correctly. This isolates the problem to.hlanguage detection.Root cause
looksLikeCpp()checks only the first 8192 characters and does not recognize a plainstruct Name : Baseclause. The file therefore falls back to the C grammar.Suggested fix
Recognize class/struct base clauses as a C++ signal and scan the full source for that signal. Adding the pattern only to the existing 8192-character sample would still fail on large headers with a long C-compatible preamble.
Regression tests should cover the plain form, a base clause after character 8192, absence of the phantom function, and a genuine C bitfield control.
Environment
@colbymchenry/codegraph 1.5.0mainat81e1f4a92fdbd9413ba73cf72c8a5408102a7897