<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/143190>143190</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang does not warn for unused variables in included files, but only main file
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          kayhayen
      </td>
    </tr>
</table>

<pre>
    Hello,

I have tried to get a warning about an unused variable in included code. I drilled it down to this, which was created with -E from an example:

```
# 1 "test.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 360 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "test.c" 2

static int x_top = 1;

# 1 "included.c" 1
static int x_middle = 1;
# 5 "test.c" 2

static int x_bottom = 1;
```

Compiling with clang-21 and older gives:

```
gcc -o test.o -c -I/usr/include/python3.11/ -I./nuitka/build/include/nuitka -I./nuitka/build/include/ -IAssertsTest.build -Wall -Wunused-variable -Werror -Wextra preprocessed.c

test.c:2:12: error: unused variable 'x_top' [-Werror,-Wunused-variable]
static int x_top = 1;
 ^
test.c:6:12: error: unused variable 'x_bottom' [-Werror,-Wunused-variable]
static int x_bottom = 1;
```

Which was very unexpected for me. Another C compiler gave warnings for all 3 variables, including `x_middle`.

Using a header file "included.h" doesn't change this. I just had a theory that maybe `.h` files are treated differently, it is applied for `.c` files as well, which is a bit of a problem due to how I use includes in my project Nuitka.

I didn't succeed in finding if this is expected behavior or not. I didn't succeed in any way with options like `-isystem` --`Wsystem-header`, not with warning mapping files, etc. it appears to me that warnings are only given for the main file. Is that itentional?

I have seen it with 

```
clang --version
Ubuntu clang version 21.0.0 (++20250529012635+c474f8f2404d-1~exp1~20250529132841.938)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-21/bin
```

```
clang --version
Debian clang version 14.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```

```
clang-19 --version
Debian clang version 19.1.4 (1~deb12u1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
```


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0Vk1v2zgQ_TX0ZSBBomTFPvjgODXWlz11kWNBkWOLLUUKJOWPS3_7YijbTdJuEyxQILETaYYz8-bNG4oQ9MEirtj8kc2fZmKMnfOrb-LSiQvaWevUZfUXGuMY37BizYr1DjpxRIheo4Lo4IARBJyEt9oeQLRujCAsjHYMqOAovBatQdAWtJVmVKhAOoU57EB5bQwq0BGUO1k6LXY6ML6BU6dlBycRQHoUERWcdOwg-wR773oKgGfRDwZZtZ7yYk1x_SnWjFdQAuM8Yoi5ZJy_fMiqTTtqEzNtWfWJcQ7l719X19dVU_ze4OYvXd8Lq8Boix8LwX-Z9fS4WIcoopagbYTzl-gGYNUTlKx6vJZ-c7whPDmXbz17rZTBV868gvn7IVsXo-tfOb5Eu1hvXD9oQwRIbZJG2EPGSyAQnFHo4aCPGH7ZrIOUkDlIGTjIJGQ7xrdj8IxvrwUxvh0usXO2ysuS8S1ku5zxrR11_CYY3xKY6pX59Op9O8h26xDQx_CZ4icDyJ6FMZA9TxzO7hzOntF75-n7HL2AwePgncQQEuSpsiuQ1Zqzal3SByQn-uPtTDD-kNrJ-AOw-eP1eMY3P4Vm86d3aABs_ull-OaD4afW_q8M3mXF832Ij-gvMFo8DyhpmPfOQ485rK2LHXrYgEwMIqKQulzlJCRDakZ1TzvJw9RA4htrihuxWVPkU-B_QtIi6FAQ9_Y6VftjPDoiunIYLOMPEWQn7AGT9pAsfR1DhE4oEBA7dP4CsRMRenFpkeLlHWuKdGgA4UkKJ4VSer9HjzaaS8oxgg4ghsHoa8XkK1_4BjihMT_kjsyh1RHcHohdrjXYgxqRlLFzJ9jBGPCmo4E0tb-Q3VeUEf5OLM9vKq20mqoLo5RIKmthr20CTe9TsRTw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