Issue |
133453
|
Summary |
[clang-tidy] `HeaderFilterRegex` does not work if `.clang-tidy` is in subdirectory
|
Labels |
clang-tidy
|
Assignees |
|
Reporter |
tearfur
|
Specifying `HeaderFilterRegex: .*` in the `.clang-tidy` file in a subdirectory doesn't seem to take effect during compilation, but running `clang-tidy --dump-config` in the subdirectory does show `HeaderFilterRegex: '.*'`.
It works as expected if I move the `.clang-tidy` file to the project root, then clean and build.
The output of running `clang-tidy --dump-config` in the subdirectory is the same no matter `.clang-tidy` is placed in the project root or the subdirectory.
This CMake project demonstrates the issue:
[header_filter_subdir.zip](https://github.com/user-attachments/files/19507895/header_filter_subdir.zip)
<details>
<summary>Here are my detailed reproduce steps</summary>
Only relevant command output are shown.
#### In host machine
```console
$ docker run -it fedora:41 bash
$ docker cp header_filter_subdir/ ${CONTAINER}:/root
```
#### In Docker container
```console
# cd
# dnf update
# dnf install @c-development cmake git ninja-build
# git clone https://github.com/llvm/llvm-project.git
# cd llvm-project/
# cmake -S llvm -B build -G Ninja -DLLVM_ENABLE_PROJECTS='clang;lld;clang-tools-extra' -DCMAKE_BUILD_TYPE=Release
# cd build/
# cmake --build .
# cmake --install .
# clang --version
clang version 21.0.0git (https://github.com/llvm/llvm-project.git 316bb89c942c1a1cf61d3e673030f82d6f0b8acf)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
# cd ~/header_filter_subdir/
# CC=clang CXX=clang++ cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
-- The C compiler identification is Clang 21.0.0
-- The CXX compiler identification is Clang 21.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/local/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for clang-tidy
-- Looking for clang-tidy - found
'/usr/local/bin/clang-tidy' '--version'
LLVM (http://llvm.org/):
LLVM version 21.0.0git
Optimized build.
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /root/header_filter_subdir/build
# cd build/
# cmake --build .
[2/4] Building CXX object print/CMakeFiles/my_print.dir/print.cpp.o
/root/header_filter_subdir/print/print.cpp:5:21: warning: parameter 'i' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]
5 | void print_impl(int const i);
| ^~~~~
[4/4] Linking CXX executable header_filter_subdir
# cd ../print/
# clang-tidy --dump-config | tee subdir.out
# mv .clang-tidy ..
# cd -
/root/header_filter_subdir/build
# cmake --build . --target clean
# cmake --build .
[1/4] Building CXX object CMakeFiles/header_filter_subdir.dir/main.cpp.o
/root/header_filter_subdir/print/print.h:4:16: warning: parameter 'i' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]
4 | void print(int const i);
| ^~~~~
[2/4] Building CXX object print/CMakeFiles/my_print.dir/print.cpp.o
/root/header_filter_subdir/print/print.cpp:5:21: warning: parameter 'i' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]
5 | void print_impl(int const i);
| ^~~~~
/root/header_filter_subdir/print/print.h:4:16: warning: parameter 'i' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]
4 | void print(int const i);
| ^~~~~
[4/4] Linking CXX executable header_filter_subdir
# cd -
/root/header_filter_subdir/print
# clang-tidy --dump-config | tee rootdir.out
# diff subdir.out rootdir.out # no output
# grep -P ^HeaderFilterRegex subdir.out
HeaderFilterRegex: '.*'
```
</details>
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs