

C++ Static Analysis Tool
source link: https://dev.to/kiennguyenchi/c-static-analysis-tool-4f46
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Introduction
This week, I work on my Static Site Generator (SSG) - Potato Generator. I plan to implement a source code formatter for my project, which is clang-format and a linter, which is clang-tidy.
Implement the clang-format
- Using CMD, I install clang-format by npm.
npm install clang-format
- Then I create .clang-format file by the command:
clang-format.exe -style=llvm -dump-config > .clang-format
- I download Clang Format Editor to test custom format. We can use this app to modify our format for the code. In this case, I use the default format. The app will show the options with switches to modify format (which is convenient), differences between current source code and formatted source code:
- I run the editor on the all .cpp files and .h files in my project with style WebKit to format my code.
clang-format -i -style=WebKit *.cpp *.h
If you are using Visual Studio Code, you can:
- Install clang-format extension
- Use Shift+Alt+F to format your current file
Implement clang-tidy
- I install linter clang-tidy
- After installation, I run the tool by this command on cmd
clang-tidy --checks='modernize*, readability*' filename.cpp -- -std=c++17
- It will show a list of warnings and errors in my code.
- In my situation, it shows that I should replace the return type of string to auto, which I do not prefer to do, so I keep that warnings.
warning: use a trailing return type for this function [modernize-use-trailing-return-type]
string getURL();
~~~~~~ ^
auto -> string
If you are using Visual Studio Code, you can:
- Install clang-tidy extension
- It will automatically read through your file and show errors/warnings
Conclusion
You can take a look at by implementation and instructions to build Static Analysis Tool for C++ program with clang-format and clang-tidy in my commit.
Overall, these tools are extremely helpful to restructure the code in nice format and eliminate all the warnings and errors from the code. It is a useful tool for developers to contribute on other project in open-source world.
Recommend
-
99
Hello everyone, welcome to article number 7 of the series. Before we jump into other examples, I think it would be nice to check the quality of the code I wrote so far to support the previous…
-
77
When PHP 5.2.4 was released in August 2007, the world was reading the last instalment of the Harry Potter series, watching Transformers in theatres, and following a junior senator from Illinois as he…
-
59
Proposal: a common interface for modular static analyses for Go Alan Donovan, 9 Sep 2018 Public Prototype: https://go-review.googlesource.com/c/tools/+/134935 This document proposes a new public interface for modular static analyses. For our...
-
63
[In this reprinted #altdevblogaday in-depth piece, id Software co-founder and technical director John Carmack
-
56
In this episode, Donn and Kaushik talk to Uber’s Manu Sridharan on static code analysis. Manu’s a badass who did his PhD on the subject! He explains how static code analysis works, how Uber leverages these tools in their...
-
60
(This blog covers the implementation details of cargo-call-stack
-
15
Jun 22, 2021 - 8 minute read - Comments - Automation
-
8
GoKart - Go Security Static Analysis GoKart is a static analysis tool for Go that finds vulnerabilities using the SSA (single static assignment) form of Go source code. It is capable of tracing the source of variables and function ar...
-
14
Tools to improve and control code quality can be a key success factor in a complex software project implementation. Static analyzers belong to such tools. Nowadays, you can find various static analyzers: from free open-source to cross-functio...
-
10
My journey of building Skott, an open-source Node.js library (2 Part Series) ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK