You have two problems to solve:
- Getting the inheritance graph across a large C++ application
- Discovering the diamonds
The first part is complex because parsing C++ to obtain this inheritance information accurately is hard (C++ itself is insanely hard to parse, then you have the complications of preprocessor conditionals, include files, macros and templates). You need a full C++ front end to do this, and an organized attack to collect the inheritance information.
Our DMS Software Reengineering Toolkit with its C++ front end can be used to extract this kind of information. You can configure DMS to parse all of your compilation units and perform name/type resolution; this handles all the preprocessing/template resolution and produces, for each compilation unit, both ASTs for the program (which you don't need for this task) as well as accessible symbol tables, which contain declarations of classes and and desired A-inherits-from-B information. A simple symbol-table scan can produce the inheritance information for each compilation unit.
You then need to assemble that information to get an inheritance graph for your system. It should be obvious that you literally want to construct the inherits-graph.
With that graph, diamond discovery is basically easy:
- For each node, build an empty hash-set of children that stores path-to-child
- Enumerate and record all paths from each node to its children using a bottom-up enumeration of inheritance paths (easily implemented using a depth first search)
- Anytime you encounter a child twice from a node, the hash-set will contain the paths to that child; two paths --> diamond
- Mark that node as having a diamond to avoid re-enumerating all sub-paths
You can implement that diamond-finder in using software other than DMS, but you could implement using DMS's internal procedural programming language, too, which would avoid the step that exports the inheritance information.
- DMS with C++ front end parses code accurately
- Raw inheritance information per compilation unit can be collected
- Sets of such data provide inheritance graph
- Algorithm to find diamonds is pretty easy to code.
Since DMS is my company's product, don't take this as a recommendation, merely a note that DMS exists and can do OP's task.