<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/83025>83025</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy ignores #line directives when reporting diagnostics.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
matt-gretton-dann
</td>
</tr>
</table>
<pre>
`clang-tidy` is ignoring `#line` directives when reporting diagnostics. This is different behaviour to `clang`.
Given the following test-case (foo.cpp):
```cpp
#line 20 "not-the-file-name.cpp"
int foo(void) {
goto bar;
return 10;
bar:
return 20;
}
```
Running clang-tidy as follows:
`./llvm-project/build/bin/clang-tidy --checks '*' foo.cpp`
Produces the following output:
```text
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "foo.cpp"
No compilation database found in /Users/matgre01/repos or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
9 warnings generated.
/Users/matgre01/repos/foo.cpp:2:5: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace [llvmlibc-implementation-in-namespace]
2 | int foo(void) {
| ^
/Users/matgre01/repos/foo.cpp:2:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
2 | int foo(void) {
| ~~~ ^
| auto -> int
/Users/matgre01/repos/foo.cpp:2:9: warning: redundant void argument list in function definition [modernize-redundant-void-arg]
2 | int foo(void) {
| ^~~~
/Users/matgre01/repos/foo.cpp:3:3: warning: avoid using 'goto' for flow control [cppcoreguidelines-avoid-goto,hicpp-avoid-goto]
3 | goto bar;
| ^~~~~~~~
/Users/matgre01/repos/foo.cpp:5:1: note: label defined here
5 | bar:
| ^
/Users/matgre01/repos/foo.cpp:4:10: warning: 10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
4 | return 10;
| ^
/Users/matgre01/repos/foo.cpp:6:10: warning: 20 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
6 | return 20;
| ^
```
Note that the errors are reported as being at lines in `.../foo.cpp` and not `not-the-file-name.cpp` as I would expect.
I have tested and observed this behaviour with clang-tidy built from main (commit e521752c04a479e3751003645a728667f3199d24) and v17.0.6 on a Mac (as shipped with Homebrew).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMV0tz2zYQ_jXQZYcaEHxJBx3kh9p0GjfTtOcOBCxJpCTAAUAp7sG_vQNQkhnZycTppZzE9uCx2O_DPj5w51SjETekuCHF3YKPvjV203Pvk8ai90Ynkmu92Bv5uCElFR3XTeKVfCQlBeVANdpYpRsgJSUs65TGMCOVReHVAR0cW9RgcTDWh3VS8UYb55VwS4A_2mDDgVR1jRa1hz22_KDMaMEbOJ9ISrok9I7Q7fTzJ3VADb5FqE3XmWMw7NH5RHCHQNiqNmYphoGwNcm2853BzfgvzE4jk9fAKBDGtPGJbzGpVYeJ5j1OZti0VmkPtTGErQ5GScLWQKqbaQqgMd7AnluSXYYs-tFqSOllLM5vr-bZ8zyp7q4cnXv_-6h1wPp8DcDdiQP3EumSsF3XHfpksOYTCk_Ybj-qTobfShO2m9lJEtGi-NsBYRVhW8IqOJP4pQ8frJGjQHdFvxn9MPqvse3xs5-G7q01Fo6t6hC8fYw3Z6AzXAIHYfpBddwro0Fyz_fc4cXkrRk7Cdp44KM3iUSPwr-6BWpjIdxguNFLKJzu8MF8bc-oJSgNhO3-dGgdYbue-8YiTQnbhQh2YCxw_QgDj7E6Rbmxj5PlWn1GmcyMJzMMMAduBoz3GHfMkcKDATeKdvLe2OsjPjmj33TCLx9_e3jLAecIOyrfmtFD3fHGnXJvDUduw6yDBjVa7lGe0_LrnBG2O19BtmUk2xbBjZOl8KdE0XE73UY_ulACALXojEMZ_VBTqhNW_fru5vavh-37-48ftrf3IUZDirqBCwRS3IRY79ReJKofOuxR-4kkpZPLOlLcnb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