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

    <tr>
        <th>Summary</th>
        <td>
            clangd -Wunneeded-internal-declaration false positive diagnostic, doesn't show in clang++
        </td>
    </tr>

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

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

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

<pre>
    Hi,
I have this code (sorry it has Qt, I'm not able to reproduce it without it):
```cpp
#include <QObject>
#include <iostream>

namespace {
void bar()
{
    std::cerr << "Hello from bar\n";
}
}

void foo()
{
    auto x = new QObject;
 QObject::connect(x, &QObject::destroyed, x, [] (const auto& ptr) {
 bar();
    });
    delete x;
}

int main()
{
 foo();
}
```
This code results in `bar()` being called and "Hello from bar" being printed. However, when I open this file in my editor, where I use clangd, I get a warning that says:
```
clang: Function 'bar' is not needed and will not be emitted (-Wunneeded-internal-declaration)
``` 
This is wrong, because it is needed, because it is called.

- I do not get this warning, when I run the compilation manually (via clang++).
- The clangd warning disappears if I remove the unused lambda argument (clang++ does warn about it).

The command I use to compile this program is:
```
clang++ -Wunneeded-internal-declaration -std=c++20 main.cpp $(pkg-config  --cflags --libs Qt6Core)
```
My clang version:
```
$ clang++ --version
clang version 18.1.8
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ clangd --version
clangd version 18.1.8
Features: linux
Platform: x86_64-pc-linux-gnu
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVU2P4zYM_TXKhXBgyxknOfgwkzTYHIp2gQV6LGiLttXKkiHJ-fj3heQ4ye5ku0DgGVEU-d4jRaFzstVEJXv7YG_7BY6-M7Z01-vVLiojruUXyfiOpXuWvh-hwxOB76SD2ggCxjfOWHsF6aFDB1894zs4Mr7uQRsPWCkCb8DSYI0YawqOZ-k7M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