Preliminary assessment of static-analysis warnings (clang-tidy)
- Dominant language
- C++
- Stars
- 403
- Forks
- 154
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 82
Description
**Describe the bug**
After a brief conversation on Slack I ran a blanket static analysis check on the whole source with clang-tidy.
I found about 2'294'900 (yes, 2 x 10^6) 242'406 unique warnings. (attached file)
This is an absolute upper bound, it is possible that only one order of magnitude less warnings actually deserve any attention.
From my experience from other code:
I estimate that about half can be automatically fix by clang-tidy (yes, the tool offers automatic solutions by doing text replacements in the source code. In my experience the tools offers fixes only when it is safe.)
Of the remaining, maybe half could be considered false positives or style related.
Maybe a bunch will solve unknown bugs or undefined behavior.
In my opinion, almost all warnings (~99%) have a positive impact if fixed but there is a decision to make to which I what point to stop. (not counting the checks that should be disable IMO, listed below).
**To Reproduce**
1. clone repo
2.
```bash
cd build
export OMPI_CXX=clang++
export OMPI_CC=clang
cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DBUILD_AFQMC=1 -DQMC_MIXED_PRECISION=1 -DCMAKE_BUILD_TYPE=Debug -DMPIEXEC_PREFLAGS="--allow-run-as-root;--bind-to;none" -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-checks=*" ..
make 2>&1 | grep warning | tee clang-tidy-warnings.txt
```
3. Sit tight
4. Inspect `sort clang-tidy-warnings.txt | uniq` (file attached)
[clang-tidy-warns.zip](https://github.com/QMCPACK/qmcpack/files/8458297/clang-tidy-warns.zip)
**Expected behavior**
No warnings
**System:**
- domestic Ubuntu 21.10 compiling with clang.
**Additional context**
There is no reason to think that any of the warnings are critical.
To begin I think that this checks are for the most part useless and misleading.
(`.clang-tidy`)
```
Checks: '*,
-readability-magic-numbers,
-modernize-use-nodiscard,
-altera-id-dependent-backward-branch,
-altera-struct-pack-align,
-altera-unroll-loops,
-cert-err58-cpp,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-avoid-magic-numbers,
-fuchsia-default-arguments-calls,
-fuchsia-trailing-return,
-fuchsia-statically-constructed-objects,
-fuchsia-overloaded-operator,
-google-runtime-references,
-hicpp-vararg,
-hicpp-no-array-decay,
-llvm-header-guard,
-llvmlibc-restrict-system-libc-headers,
-llvmlibc-implementation-in-namespace,
-llvmlibc-callee-namespace
'
WarningsAsErrors: '*'
HeaderFilterRegex: '.'
AnalyzeTemporaryDtors: false
FormatStyle: file
````
Contributor guide
Assessment
This issue has not been assessed yet.