Refactor with Clang Tooling at code::dive 2018

I delivered a talk about writing a refactoring tool with Clang Tooling at code::dive in November. It was uploaded to YouTube today:

The slides are available here and the code samples are here.

This was a fun talk to deliver as I got to demo some features which had never been seen by anyone before. For people who are already familiar with clang-tidy and clang-query, the interesting content starts about 15 minutes in. There I start to show new features in the clang-query interpreter command line.

The existing clang-query interpreter lacks many features which the replxx library provides, such as syntax highlighting and portable code completion:

It also allows scrolling through results to make a selection:

A really nice feature is value-based code-completion instead of type-based code completion. Existing code completion only completes candidates based on type-compatibility. It recognizes that a parameterCountIs() matcher can be used with a functionDecl() matcher for example. If the code completion already on the command line is sufficiently constrained so that there is only one result already, the code completion is able to complete candidates based on that one result node:

Another major problem with clang-query currently is that it is hard to know which parenthesis represents the closing of which matcher. The syntax highlighting of replxx help with this, along with a brace matching feature I wrote for it:

I’m working on upstreaming those features to replxx and Clang to make them available for everyone, but for now it is possible to experiment with some of the features on my Compiler Explorer instance on

I wrote about the AST-Matcher and Source Location/Source Range discovery features on my blog here since delivering the talk. I also wrote about Composing AST Matchers, which was part of the tips and tricks section of the talk. Over on the Visual C++ blog, I wrote about distributing the refactoring task among computers on the network using Icecream. My blogs on that platform can be seen in the Clang category.

All of that blog content is repeated in the code::dive presentation, but some people prefer to learn from conference videos instead of blogs, so this might help the content reach a larger audience. Let me know if there is more you would like to see about clang-query!

13 Responses to “Refactor with Clang Tooling at code::dive 2018”

  1. Daniel Kim Says:

    Your presentation material link is broken. You linked “” but it opens “” in chrome.
    I already got pdf from “”. I just want to let you know because this presentation is interesting.

  2. steveire Says:

    Thanks, I fixed the link!

  3. Yitzhak Mandelbaum Says:

    Steve, you mentioned in the talk (IIRC) a way to avoid matching against code that is generated by the compiler (like generated constructors/methods and range-fors). Can you expand on that? Have you augmented the AST to expose this property and/or added controls for how matchers work (which I remember us discussing on the bug for ignoreImplicit())?

  4. Ubuntu Weekly Newsletter Issue 560 – Mags Forum Technology Says:

    […]…codedive-2018/ […]

  5. Sys Says:


  6. Debugging Clang AST Matchers | Steveire's Blog Says:

    […] Dreamer, but not the only one. « Refactor with Clang Tooling at code::dive 2018 […]

  7. free wordpress hosting trial Says:

    free wordpress hosting trial

    400 The plain HTTP request was sent to HTTPS port

  8. Says:

    Refactor with Clang Tooling at code::dive 2018 | Steveire's Blog

  9. Home Flip Says:

    Home Flip

    Refactor with Clang Tooling at code::dive 2018 | Steveire's Blog

  10. Says:

    Refactor with Clang Tooling at code::dive 2018 | Steveire's Blog

  11. Audi Says:


    Refactor with Clang Tooling at code::dive 2018 | Steveire's Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: