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

    <tr>
        <th>Summary</th>
        <td>
            Clangd false export decalaration error if C++20 module declaration is in an included file
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    File `inc.h`:
```cpp
export module B;

import A;
```

File `b.cppm`:
```cpp
#include "inc.h"

export int //<<< Error: Export declaration can only be used within a module interface unit after the module declaration
BFunc()
{
    return TestFunc() + 1; // <<< No error for TestFunc() which is imported from A.
}
```
This is successfully compiled by Clang, but clangd produces this error. Note that there is no error for `TestFunc()` call which is from `A` module, its implementation is also properly navigated (and if `#include` is commented out, error at this place is shown as expected). I am not sure if such module declarion in a header file is correct as per C++ standard but looks like it should at least be consistent with Clang behavior. Also, please note, that exactly the same behavior is visible when including this file by `-include` command line option.

```
I[11:23:41.079] --> textDocument/clangd.fileStatus
V[11:23:41.079] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///home/artyom/projects/asio-awaitable-module-problem-demo/b.cppm"}}

V[11:23:42.834] <<< {"id":63,"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[{"code":"export_not_in_module_interface","message":"Export declaration can only be used within a module interface unit after the module declaration","range":{"end":{"character":6,"line":2},"start":{"character":0,"line":2}},"relatedInformation":[],"severity":1,"source":"clang"}],"triggerKind":2},"range":{"end":{"character":0,"line":2},"start":{"character":0,"line":2}},"textDocument":{"uri":"file:///home/artyom/projects/asio-awaitable-module-problem-demo/b.cppm"}}}
```
```
$ /opt/clang-latest/bin/clangd --version
clangd version 16.0.0 (https://github.com/llvm/llvm-project.git ee761374f797a47919ec8f9f49f9b8b1b20573e8)
Features: linux
Platform: x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