I recently updated my project and its CI pipelines to use C++20 features. When I changed the compiler settings to use C++20, clang-tidy started to emit the following warning (I treat them as errors) for all my checked files:
error: invalid case style for template parameter 'expr-type' [readability-identifier-naming,-warnings-as-errors]
I could narrow it down to the following minimal example using CMake and a clang-tidy config file:
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(clang_tidy_warning LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(clang_tidy_warning main.cpp)
.clang-tidy
Checks: >
readability-*,
WarningsAsErrors: '*'
CheckOptions:
- {key: readability-identifier-naming.TemplateParameterCase, value: lower_case}
- {key: readability-identifier-naming.TypeTemplateParameterCase, value: CamelCase }
- {key: readability-identifier-naming.TemplateParameterPrefix, value: t_ }
- {key: readability-identifier-naming.TypeTemplateParameterPrefix, value: T_ }
main.cpp
#include <iostream>
int main() { return 0; }
You should be able to reproduce it in Ubuntu 20.04 with the following commands starting in the root directory:
mkdir build
cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=DEBUG ..
run-clang-tidy-12 -quiet
The error/warning disappears if you do one of the following things:
- remove the specified check options from the config file
- set the c++ standard to 17
- remove the
#include
in the main file
Exchanging iostream
with another standard library header didn't help, but I have not tested them all. It is also worth mentioning that all other possible clang-tidy configuration options do not cause this error. I had nearly all of them in the original config file and removed the ones that do not cause the error. It seems like only the TemplateParameter
and TypeTemplateParameter
suboptions are affected by this. I have tested clang-tidy versions 9, 10, and 12. All emit the same warning. I also tested passing different compilers (clang 12 and gcc10) to CMake. Did not change anything (do not know if clang-tidy is even affected by the compiler choice, I guess not). I am using Ubuntu 20.04 (up-to-date) and you can also reproduce the error in a GitHub action runner.
So my questions are. Is this a (known) bug or is there any incompatibility with C++ 20 in this clang-tidy setup? If it is already known, can you give me an explanation of why it occurs and how to fix it?
EDIT
As Lawrence Benson mentioned in the comments, this might be also OS-related. He couldn't reproduce on a Mac, but on Ubuntu.
Related bug report
Here is the link to a related bug report found by 0x5453: click me
Update: As "Buster" pointed out in the comments, the bug report has been moved here