<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/118009>118009</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] InheritParentConfig does not seem to work consistently with HeaderFilterRegex
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
PWVEC
</td>
</tr>
</table>
<pre>
I've encountered a strange behavior regarding "InheritParentConfig" and "HeaderFilterRegex" (other options might be affected as well...).
Given the following setup in a project:
```bash
.
├── .clang-tidy
└── src
├── .clang-tidy
├── external.h
├── internal.h
└── main.cpp
```
With the following file contents:
```bash
$ cat .clang-tidy
Checks: "-*,modernize-use-trailing-return-type"
HeaderFilterRegex: ".*"
$ cat src/.clang-tidy
InheritParentConfig: true
HeaderFilterRegex: 'internal'
$ cat src/internal.h
int GetSomeValue();
$ cat src/external.h
int GetSomeLibValue();
$ cat src/main.cpp
#include "internal.h"
#include "external.h"
int GetSomeValue() { return 42; }
int main() {
return GetSomeValue() + GetSomeLibValue();
}
```
The expectation is that when clang-tidy is run on "main.cpp", it will report the diagnostics for "internal.h" but not for "external.h".
But this does not work consistently. It seems relevant in which workding directory clang-tidy is invoked.
```bash
$ clang-tidy src/main.cpp 2>/dev/null
PATH/TO/PROJ/src/external.h:1:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
1 | int GetSomeLibValue();
| ~~~ ^
| auto -> int
PATH/TO/PROJ/src/internal.h:1:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
1 | int GetSomeValue();
| ~~~ ^
| auto -> int
PATH/TO/PROJ/src/main.cpp:4:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
4 | int GetSomeValue() { return 42; }
| ~~~ ^
| auto -> int
PATH/TO/PROJ/src/main.cpp:6:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
6 | int main() {
| ~~~ ^
| auto -> int
```
The diagnostic in "external.h" should be filtered, IMO.
If I run clang-tidy in "src", then this works as expected:
```bash
cd src/ && clang-tidy main.cpp 2>/dev/null
PATH/TO/PROJ/src/internal.h:1:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
1 | int GetSomeValue();
| ~~~ ^
| auto -> int
PATH/TO/PROJ/src/main.cpp:4:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
4 | int GetSomeValue() { return 42; }
| ~~~ ^
| auto -> int
PATH/TO/PROJ/src/main.cpp:6:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
6 | int main() {
| ~~~ ^
| auto -> int
```
Notably, if I dump the configuration with "--dump-config" the resulting configuration is identical in both cases and it clearly sets "HeaderFilterRegex" to "internal".
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsV1Fv2zgS_jX0y8CCPLIt-8EPshO3Odxdg17RPlPUSOKVJg2Ssut96G9fkHZiOXHSYBdbLBY1AsSQZoacb2Y-f8Odk40mWrDJkk1uBrzzrbGL-y-fb1eD0lSHxR3DfEdAWphOe7JUAQfnLdcNQUkt30ljwVLDbSV1AwzxTrdkpb_nlrRfGV3LhiEC11V4-554RXYtlSf7kRr6Ft4xnBnfkgWz9dJoBxvZtB5KAl7XJHw41cGelEqShOE8YWnB0uKd3JEG3xLURimzDxdw5LstSA0cttb8n4RnWXE0Z9P0-Fdy17K0iFFukc3HbL46fZmlj18gEYrrZuhldehZjq9YOitYWgAAvD3ej6zpmyeruUraNxhL_YLxtdtuuNSJ2G77kBwR-iJ9-wTPWioCYbQn7d2LUDIcg-D-SYqrlsTX4BQKP2RYMFxtTEVWy99o2DkaesulkroZWvKd1UN_2BJDZGnxvE-OYZIYBk_XOB0b8Mf15eHX2jArwNuOXg6fPwDJML92xAXOUnt4R_5_ZkOfueqI4YzhnGXLa54X5ex5_luWP3buVwwzqYXqKgpo9O5zxOTibe_MB8Su3xlYvoRjCWCMLFsCy2_ODuH4s2HssJPxtVC4fDW3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