DEV Community

Rudy Chung
Rudy Chung

Posted on

OSD600 Lab 7

What I did this week

This week, I added static analysis tools to my SSG project. The tools I added were the C++ code formatter clang-format and C++ code linter clang-tidy. Both of them can be integrated into Visual Studio 2022 using the Clang Power Tools extension, which made it handy to configure and use.

Clang Power Tools

In regards to the Clang Power Tools extension, it's usage is rather simple. After installing the extension, right-clicking the toolbar should show all available toolbar extensions.

toolbars

The Clang Power Tools toolbar extension appears as so:

clang toolbar

Clang Power Tools also contains extensive configuration options. I played around with them until I got the code formatting I desired and saved those configurations into a .clang-format file to be used in the command-line. I did the same with clang-tidy, saving them into a .clang-tidy file.

clang-formatting and clang-tidying my code

Using clang-format, I didn't find many problems with my code, since I used the built-in code formatter in VS2022 often. However, I did find that there were some formatting standards that I preferred, so I set clang-format to adjust my code to meet those standards.

With clang-tidy, there were a few issues that I had not spotted. These were mostly related to performance with arguments that were received as copies rather than references. I made those changes accordingly. There were also some minor conventions that I had neglected to follow, so I had clang-tidy adjust those as well.

Problems

I struggled a lot in setting up the clang tools in my project. Although the Clang Power Tools extension was quite easy to set up, the command-line versions of them was a different story. At first I downloaded the LLVM installer from here. But, I realized that these tools were accessible via modifying the Visual Studio 2022 installation using the Visual Studio Installer. I decided to do the latter, since my project did not require all of the LLVM tools, though I did provide a link to it in my contributing document for those who do not use VS2022.

install

By adding the components using the Visual Studio Installer, the clang tools are accessible through the terminal in VS2022. They can be executed using their commands as though installed through LLVM.

What I learned

In this lab, I learned about static analysis tools in C++. I had not previously used them, instead sticking to the standards set by my professors and using the built-in code formatter in Visual Studio. Although I do have some experience with static analysis tools in Javascript/Typescript, I did not know of any such tools for C++. They are quite a bit more finicky in C++ (at least in my experience) however they are just as useful.

Top comments (0)