Abstract: I wanted to see if a parameter in a pure virtual function was ever used in any of the implementations. Learn how to do it.
Is this parameter dead?
It’s probably more polite to ask if the parameter is used, but either way, it’s a frequent question. For example, yesterday I was looking at Understand’s context menu code to see how hard it would be to get a list of available actions for a fancy command search. The important function is:
virtual QList<QAction *> contextActions(
Project *project,
QWidget *widget,
QMenu *parent) = 0;
Hmm, what’s this widget parameter? I thought the context menu only cared about the selection. Like, a “Calls Graph” is only going to show up when a function with calls is selected. Does this widget parameter matter?
One way of knowing if the parameter matters is to see the values that are passed in. If the value is always the same, then the parameter is essentially dead. There’s already a blog article on how to get that information.
Why a new interactive report?
In this case, though, what I really want to know is how the parameter is used in the function. Silly Natasha, you’re an Understand engineer. If anyone should know how to check the Information Browser first, it’s you!
Yes, thanks inner monologue. I DID check the Information Browser. Of course it’s the first thing I’d try. But the Information Browser only tells me how the parameter is used in the ContextMenuProvider::contextActions method, which, as a pure virtual method, is … not at all. I need to know how it’s used in all the methods that override the pure virtual function.
It turns out that the method is overridden by 18 methods. I’ll admit, I started by checking the first few methods by hand. Show the overridden method in the Previewer by double clicking it in the Information Browser, find the parameter, ask for information on it, check the Information Browser for references, go back to the parent method, repeat. But that’s tedious and 18 methods is way too many. So, I wrote an Interactive Report to do it for me: “Parameter Overrides”.
The Interactive Report
The first part of the report is an overview and sanity check. I want to make sure that I found all the overriding functions and matched the parameter correctly. So, I’ll put in a table for it that also shows the reference count by function.
In my case, there are 19 functions from the starting function plus the 18 overriding functions. It turns out only four of them use the parameter, and that the parameter name was not changed in any of the overriding functions:

Now I want a way to quickly navigate to the reported references. So the second part of the report is a references table. Tables are so pretty and filterable, I must use them everywhere. Anyway, my six references:

My Answer
Clicking the line number opens the location in the editor. The other columns are synced to the entity shown. Hmm, there’s a reference in the GraphDisplayMenuProvider. Oh, yeah. I wrote that. Totally forgot. That’s how the context menu shown on a selected range in the editor offers a control flow graph allowing you to quickly navigate to the relevant part of the graph.
So, the parameter is not dead. Furthermore, re-using this function in a fancy command search bar would probably need the search bar to pass in the active window so that things like the option to open a control flow graph to the location in the editor would show up.
If you’re also trying to find parameter uses across an inheritance tree, try out the “Parameter Overrides” Interactive Report. Facing a different question? Tell us about it to help us improve and to help other engineers who likely have the same question!