Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sebastianbach/cpp-check-suite

Checks for C++ code.
https://github.com/sebastianbach/cpp-check-suite

asan clang-format clang-tidy coverage cpp cppcheck ubsan valgrind

Last synced: about 1 month ago
JSON representation

Checks for C++ code.

Awesome Lists containing this project

README

        

Sample project showing how to use sanitizers and analyzers to check C++ code.

# Install Dependencies

Example platform is Linux/Ubuntu using GCC:

```shell
sudo apt-get update

sudo apt-get install build-essential cmake cppcheck clang-format clang-tidy valgrind

pip install gcovr
```

# Checks

## Compiler Warnings

Enable extensive compiler warnings-as-errors with the custom **cmake** option ```ENABLE_WARNINGS```.

```shell
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_WARNINGS=ON ..
cmake --build . -j
```

## Cppcheck

Use **cppcheck** with the ``compile_commands.json`` file generated by **cmake**.

```shell
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
cppcheck --project=compile_commands.json --cppcheck-build-dir=./temp/cppcheck --error-exitcode=1 --enable=all
```

## clang-format

Use **[clang-format](https://clang.llvm.org/docs/ClangFormat.html)** to check the code style.

```shell
clang-format --dry-run -Werror --style=file src/bad_code.cpp
```

## clang-tidy

Use **[clang-tidy](https://clang.llvm.org/extra/clang-tidy/)** to analyze code patterns.

Clang tidy can be used by **cmake** via [CXX_CLANG_TIDY](https://cmake.org/cmake/help/latest/prop_tgt/LANG_CLANG_TIDY.html) enabled with:

```shell
cmake -DENABLE_CLANG_TIDY=ON ..
cmake --build .
```

## ASAN (AddressSanitizer)

Use the **[AddressSanitizer](https://clang.llvm.org/docs/AddressSanitizer.html)** to check for memory issues at runtime.

```shell
cmake -DENABLE_ASAN=ON ..
cmake --build .
ctest --output-on-failure
```

## UBSAN (UndefinedBehaviorSanitizer)

Use the **[UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html)** to check for cases of [undefined behaviour](https://en.cppreference.com/w/cpp/language/ub) at runtime.

Enable and run with:

```shell
cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_UBSAN=ON ..
cmake --build . -j
ctest --output-on-failure
```

## Valgrind

Use **[Valgrind](https://valgrind.org/)** to check for memory issues at runtime.

```shell
cmake -DUSE_VALGRIND=ON ..
cmake --build .
ctest -T memcheck --output-on-failure
```

## Coverage

Create a coverage report using **[gcovr](https://gcovr.com/en/stable/)** to see how much of the code is executed during tests.

```shell
cmake -DENABLE_COVERAGE=ON ..
cmake --build . -j
ctest

cd ..
gcovr -r . --html --html-details -o build/coverage/coverage.html
```