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

    <tr>
        <th>Summary</th>
        <td>
            [C++20] [Modules] [clangd] We shouldn't see Macro Definition in the importee
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clangd,
            clang:modules
      </td>
    </tr>

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

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

<pre>
    Currently, the macro definition in a named module unit can be found in the importee by clangd. However, this is incorrect since the Macro Definitions inside a named module unit is invisible outside the TU.

Following is a simple reproducer:

```
// A.cppm
export module A;
#define MODULE_NAME A

// main.cpp
import A;
void foo() {
    return MODULE_
}

// compile_commands.json
[
    {
      "directory": "/home/chuanqi.xcq/workspace.xuchuanqi/cxx-modules-examples/duplicate_header",
      "command": "/home/chuanqi.xcq/workspace.xuchuanqi/llvm-project-for-work/build/bin/clang++  -fprebuilt-module-path=/home/chuanqi.xcq/workspace.xuchuanqi/cxx-modules-examples/duplicate_header -std=c++20 -o /home/chuanqi.xcq/workspace.xuchuanqi/cxx-modules-examples/duplicate_header/main.cpp.o -c /home/chuanqi.xcq/workspace.xuchuanqi/cxx-modules-examples/duplicate_header/main.cpp -I.",
      "file": "/home/chuanqi.xcq/workspace.xuchuanqi/cxx-modules-examples/duplicate_header/main.cpp"
    }
]
```

And compile them by the following command:

```
clang++ -std=c++20 --precompile -c A.cppm -o A.pcm
```

Then in the editor, when we type `MODULE_` in main.cpp, we'll get:

![image](https://user-images.githubusercontent.com/68680648/200776839-001331bb-3074-4044-b3e1-32cd583331c7.png)

But this is clearly incorrect.

---

BTW, although the bug shows in clangd, we should fix it in the clang part. 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1VUtv4zgM_jXORbAhP-LHwYc0mWIX2O5eOpi5FbLMxJqVLY8lN-m_X9KPNukU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