In C++, entities without a name legally exist—anonymous namespaces and structs. For example, a nested struct class Widget { struct { int x, y; } coords; };.
At first, we encountered this while parsing the XML from the old generator: it output empty <compoundname> tags for anonymous namespaces, causing our parser to crash with a scream. We taught it to painlessly collapse them into the global scope. But the real war began when we reached anonymous structs in our new native AST parser based on libclang.
The Chaos of Absolute Paths
When the native libclang parser encounters an anonymous struct, it needs to name it somehow inside the Abstract Syntax Tree (AST). And the compiler honestly generates a purely technical name for it: (unnamed struct at /home/user/workspace/repo/include/widget.h:42:5).
The problem is that this name includes the absolute path to the file on the hard drive. On one developer's machine, the path is one thing; on the CI server, it's another. Our tests and API snapshots (golden fixtures) started going crazy, producing thousands of false changes on every run. We needed a stable, platform-independent identifier.
Legacy Hallucinations
We went to see how good old Doxygen solved this problem, intending to copy its behavior. And we grabbed our heads.
It turned out that Doxygen, as the type of an anonymous field, simply took the name of the outer, parent class! That is, according to the legacy tool, the type of the coords field was... struct Widget.
From the perspective of C++ semantics, this is absolute nonsense. A field cannot have the type of its own class (unless it's a pointer), and an anonymous struct inside a class is certainly not the class itself! But it worked: it was a stable, predictable identifier, independent of file system paths.
Simulating Madness
We faced a tough choice: invent our own logical format for anonymous structs and break compatibility with thousands of already generated documentation pages, or force the new, strict parser to copy the madness of the old one.
We chose the latter. We wrote a patch that checked the compiler's AST node via the is_anonymous() method. If it was an anonymous struct, we ruthlessly threw away the honest and accurate type from libclang and hardcoded the string struct {current_class.fully_qualified_name}.
Why Not Make It Configurable?
A logical question we were asked during review: why did we simply hardcode a semantically incorrect convention instead of making the behavior configurable? Why not make the default "correct," and enable "Doxygen mode" via a special flag? After all, we already have similar flags in the parser (like extract_undocumented or include_private), where each backend has its own defaults.
The answer is a conscious choice of priorities for the current stage, not trivial laziness. The entire current phase of the project exists for a single metric: 100% parity (recall/precision) between the old and new parsers.
The reconciliation methodology requires that the parsers' outputs match wherever reasonable. If we added a config, we would still have to enable it for 100% of validation runs. Today, this configurability would not solve any real business problem; it would only bloat the code.
We created a ticket in the backlog for the future: when the native parser stops being "reconciled" and becomes the independent default path for completely new projects (which don't have a heavy history), that's when the compatibility flag will become a real choice.
Conclusion
The question "when will we allow ourselves to just be right, rather than byte-for-byte compatible" is the leitmotif of the entire migration, affecting both graph visualization logic and documentation routing. But for now, we intentionally forced a modern toolchain to generate semantically incorrect C++ code solely to match the old one bug-for-bug.
However, structural bugs are only half the trouble. In the next episode, we will talk about the caching problem: how the native parser built perfect relationships between objects when built from scratch, but irretrievably lost them if the cache folder already existed.
Originally published on our blog: https://blog.flude.guide/blog/simulating-madness-anonymous-structs
Also read us:





