View on GitHub

Clang Power Tools

Bringing clang-tidy magic to Visual Studio C++ developers

Tips & Frequently Asked Questions

πŸ‘‰ Does Clang Power Tools support clang-format ?

Yes. Starting with version 3.0 Clang Power Tools VS extension has built-in support for clang-format
Auto-format source file on save, configurable style options, file extension rules, etc.

πŸ‘‰ What Clang/LLVM tools are supported by Clang Power Tools workflows ?

πŸ‘‰ Do I need to install LLVM for Clang Power Tools to work ?

Yes. Download and install Clang for Windows (LLVM pre-built binary)
releases.llvm.org/download.html
Eg. LLVM-6.0.1-win64

We will automatically load clang from the default installation path C:\Program Files\LLVM. If you prefer to use a different location you must manually add the bin folder to PATH.

πŸ‘‰ What versions of LLVM are supported by Clang Power Tools ?

We tested Clang Power Tools with LLVM 3.9.x, 4.0.x, 5.0.x, 6.0.x and 7.0.x

πŸ‘‰ How to deal with warnings from system/third-party headers ?

Until v2.6, we’ve used the %INCLUDE% environment variable for setting clang include directories. That was equivalent to using -isystem for each directory.

Unfortunately, this caused headers included relative to those include directories to be ignored when running compiling/tidying because they were treated as system headers.

Having this brought to our attention, going forward we will use -I and -isystem to pass include directories to clang, with the following defaults:

Q: What does this mean?
A: You’ll most likely see new warnings when compiling or tidying your code-base.

Q: Will my build fail?
A: Only if you have specified -Werror (treat warnings as errors).

Q: What should I do?
A: - Make sure to include third party library dependencies via the Include directories project option. Additional include directories should point only to code you can modernize.
- Resolve remaining warnings related to your code.

Q: Can I use ClangPowerTools using the old behavior?
A: Yes. We’ve added, for compatibility reasons, a UI option that allows clang to treat additional includes as system headers. Keep in mind this means we will potentially miss some of your headers when calling clang.

You may want to use this option if using -Werror (treating warnings as errors) until you’ve reorganized your includes, since any new warnings will break your build.

Q: What about the continuous integration script (clang-build.ps1)?
A: You can specify the -treat-sai switch and it will have the old behavior.

πŸ’‘ Did you know you can automatically run Clang compile on the current source file after each MSVC compilation ?

This option was a real game changer for our team, because developers often broke CI build pipelines (Clang build). Scenario:
Developer compiles code in Visual Studio (/W4 /WX) βœ”οΈ … push commit … CI build pipeline …. broken Clang build πŸ”₯
After enabling this option (from Settings), developers immediately see when they compile a source file from VS if it also works in Clang. Each successful MSVC compile is automatically followed by a Clang compile.

πŸ‘‰ Where can I see detailed information about clang-tidy checks ?

A list of available checks that clang-tidy can perform:
clang.llvm.org/extra/clang-tidy/checks/list

πŸ’‘ Did you know you can auto tidy code on save ?

There is a setting (off by default) that enables automatic clang-tidy (fix) when the current source file is saved.

πŸ’‘ Did you know you can UNDO all the changes performed by clang-tidy ?

After performing clang-tidy on a source file opened in the VS editor, you can Undo the tidy changes (atomically) by hitting Ctrl+Z

πŸ‘‰ How can I use Clang Static Analyzer ?

Clang Static Analyzer was included into clang-tidy some time ago. As a result, you can use Clang Power Tools to run all static analyzer checks from Clang. Check our extension settings panel, in the Tidy sub-section, scroll to see and ENABLE all the checks starting with: β€œclang-analyzer-β€œ

More details here:
clang-analyzer.llvm.org/available_checks

πŸ‘‰ Does Clang Power Tools support automatic checking of CppCoreGuidelines ?

Yes. By leveraging clang-tidy support for checking CppCoreGuidelines.
You can use the cppcoreguidelines-* filter from Clang Power Tools settings, to select CppCoreGuidelines from the available clang-tidy checks.

πŸ‘‰ If I want to use a .clang-tidy file, where do I put that configuration file on the file system?

clang-tidy searches for the config file starting from the given/input source file directory, going up .. until it finds a .clang-tidy file (stops at drive root). This is the standard clang-tidy lookup mechanism.
FYI, Clang Power Tools has a setting related to this workflow:
VS Options > Clang Power Tools > Tidy > Options > Use checks from: (combo-box)

πŸ‘‰ How do I configure options for specific clang-tidy checks ?

Configuration options for specific clang-tidy checks can be specified via the .clang-tidy configuration file.
Eg.

Checks:          '-*,some-check'  
WarningsAsErrors: ''  
HeaderFilterRegex: '.*'  
FormatStyle:     none  
CheckOptions:  
  - key:             some-check.SomeOption  
    value:           'some value'  
...