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

    <tr>
        <th>Summary</th>
        <td>
            [C++20] [Modules] We may meet problems if we import first and include second
        </td>
    </tr>

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

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

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

<pre>
    Currently, the following can be accepted:

```
#include <iostream>
import foo; // assume module 'foo' contain the declarations from `<iostream>`

int main(int argc, char *argv[])
{
    std::cout << "Test\n";
    return 0;
}
```

but it will get rejected if we reverse the order of import and include here:

```
import foo; // assume module 'foo' contain the declarations from `<iostream>`
#include <iostream>

int main(int argc, char *argv[])
{
    std::cout << "Test\n";
    return 0;
}
```

Both the above examples should be accepted.

This is a limitation in the implementation. In the first example, the compiler will see and parse `<iostream>` first then the compiler will see the import. So the ODR Checking and declarations merging will happen in the deserializer. In the second example, the compiler will see the import first and the include second. So the ODR Checking and declarations merging will happen in the semantic analyzer.

So there is divergence in the implementation path. It might be understandable that why the orders matter here in the case. 
(Note that "understandable" is different from "makes sense"). Given the current scale of clang, it will be pretty hard to merge the two paths together quickly and innocently. Maybe we could only fix the problems reported one by one. So the current issue report is for summarizing such issues. And it may open for a pretty long time.

Note that MSVC's documents  said to include headers before import directly. (https://learn.microsoft.com/en-us/cpp/cpp/modules-cpp?view=msvc-170#modules-and-header-files)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVsuu2zYQ_Rp6M7AgU35p4cW1XRdZpAWaoO2WokYSe_lQyJEd5-sLUrJ9jd6miwIFChiyxMdwzjkzRxIhqNYi7thqz1bHmRioc3536AZhv6jfh3JWufq6OwzeoyV9ZfwA1CE0Tmt3UbYFKSxUCEJK7AlrVryw_Mjy23WdT7_xkRfKSj3UCKw4KBfIozCs-GGcV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