A Clang-based tool that rewrites C++ snippets into expanded source showing what the compiler generates. Usable online or as a local command-line binary.
Overview
C++ Insights shows C++ source as the compiler sees it, using a Clang-based source-to-source transformation. It exposes language features that normally stay hidden, such as compiler-provided special members, implicit casts, desugared range-based for loops, structured bindings, lambdas, and deduced types behind auto or decltype.
The output stays in C++ rather than an AST dump or assembly, which the author aimed at teaching and self-exploration. The goal is compilable transformed code where possible, though some transformations cannot be expressed as valid source. Behavior follows Clang’s reading of the AST.
You can paste snippets on the public site or run the insights binary locally. Editor plugins exist for Vim, Neovim, and Visual Studio Code. On macOS, Homebrew can install the binary. A separate Docker image packages a ready-to-use environment. Shell completion scripts cover bash, zsh, and fish for CLI options and trailing Clang flags after --.
System include paths are baked into the binary from the Clang used at build time; a helper script can collect include paths from your chosen compiler. Custom GCC installs may need a --gcc-toolchain option so libc++ paths resolve.
Key features
- Clang AST source-to-source transforms
- Lambda and range-for expansion
- Structured binding desugaring
- auto and decltype type revelation
- Implicit cast and operator visibility
- Online editor at cppinsights.io
- Vim, Neovim, and VS Code plugins
- Docker image and Homebrew on macOS
Use cases
- Teaching modern C++ mechanics
- Inspecting implicit compiler work
- Comparing source with desugared forms
- Debugging template and overload behavior
- Learning without reading assembly