Description
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 says to include headers before import directly. (https://learn.microsoft.com/en-us/cpp/cpp/import-export-module?view=msvc-170#import)