-
Notifications
You must be signed in to change notification settings - Fork 12.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C++20] [Modules] We may meet problems if we import first and include second #61465
Comments
@llvm/issue-subscribers-clang-modules |
In issue #61329 (closed in favor of this one), @ChuanqiXu9, you wrote:
I think I'm forced to put imports in headers, if I want to mix C++ modules with old style .h/.cc file pairs. And I need that mix, if I'm transitioning existing code to C++ modules. In other words, if I write a class in the old style (.h, .cc), and it's declaration needs something from a module, then I need to import that module in the header file. (?) |
My view is that anything that can be in a module should be. This means that headers are mostly just for macro definitions, and sometimes those macros will need to use something that was defined in a module. I don't see anything wrong with that. To give a really basic example, I have a macro that depends on |
A trick for transitioning existing code to C++ modules may be: https://github.com/alibaba/async_simple/blob/CXX20Modules/third_party_module/asio/asio.cppm. I mean you can have a module wrapper to wrap the current headers. Then you can import the module in the .cc files. Then I suggest to replace/refactor it step by step. |
Is the same issue? It's not import-include order but I thought it might the same underlying issue.
module;
#include <ranges>
export module Mod1;
module;
#include <nlohmann/json.hpp> // this ends up including <ranges>. I'm not sure what it does to make things screwy.
export module Mod2;
import Mod1; Errors below. Something about how the json headers include of
|
This is not the same issue. It'd better to file another issue. And if possible, it will be best and pretty helpful if you can reduce it. Currently, you can reduce it by :
Generally it may take 1 hour. (If you don't have time to reduce it, I can only make it myself. But it may take longer time to fix the bug.) Thanks~ |
Okay, I can't now, but I will try in coming days. |
I got to it faster than I thought :) #61642 |
Currently, the following can be accepted:
but it will get rejected if we reverse the order of import and include here:
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)
The text was updated successfully, but these errors were encountered: