Compiler warnings prevent software bugs BEFORE they occur. Sadly, most warnings are either undetected or disabled by default. This repository checks the warning coverage of popular C++ compilers against 72 test cases.
Each test case compiled without a warning or error is a miss. And the winner is:
- clang-tidy 21.1.8 which misses 2 warnings only. Well done 👍
- Visual Studio 2026 misses 17
- Clang 21.1.8 misses 24
- GCC 15.2.0 misses 32
- Cppcheck 2.19.0 misses 33
Note: The 📂src subfolder contains the test cases and the test results are located in 📂results (highest warning level has been enabled, also contains older/historic versions).
Required is cmake and the C++ compiler (git optionally). Then execute in a terminal window:
> git clone https://github.com/fleschutz/CWTS # or download and unzip the ZIP file (click the green button)
> cd CWTS/src
> cmake . # edit 'CMakeLists.txt' before to select a certain C++ compiler
> make -k # option '-k' means keep going, even on errors
No, compilers don't enable the highest warning level by default. All have a default warning level of 'normal', far from highest level. And each compiler supports different options to be more pedantic:
| Compiler | Options Needed | Description |
|---|---|---|
| Clang | -Weverything -pedantic |
|
| clang-tidy | -checks=*,-modernize* |
all checks except 'modernize' hints |
| Cppcheck | --enable=all |
|
| GCC | -Wall -Wextra -pedantic -Wundef |
-Wall and -Wextra do not enable all warnings! To keep backwards compatibility, -Wall is basically, "All warnings as of 1990." -Wextra covers a lot of the newer warnings, but still misses a few. |
| Visual Studio | /Wall |
It means a project is compiled with the highest warning level and zero compiler warnings are acceptable.
Introducing the Zero Warnings Policy by enabling the highest warning level often results in hundreds or thousands of warnings. To get started you may want to begin with a lower warning level first. Then fix those warnings and gradually dial up the warning level.
As soon as there are no more warnings turn warnings into errors to enforce the Zero Warnings Policy from now on. That way warnings can no longer be ignored because the build fails. The corresponding compiler options are -Werror for Clang and GCC and /WX for Visual Studio.
- Contributions, suggestions, and improvements are welcome!
- Open an Issue if you encounter bugs or have feature ideas.
- Create a Pull Request if you'd like to improve something.
This open source project is licensed under the CC0 license. All trademarks are the property of their respective owners.