This is an archive of the discontinued LLVM Phabricator instance.

[C++20][Modules] Fix named module import diagnostics.
ClosedPublic

Authored by iains on Jan 3 2023, 2:57 PM.

Details

Summary

We have been incorrectly disallowing imports of named modules in the
global and private module fragments.

This addresses: https://github.com/llvm/llvm-project/issues/59688

Diff Detail

Event Timeline

iains created this revision.Jan 3 2023, 2:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2023, 2:57 PM
Herald added a subscriber: ChuanqiXu. · View Herald Transcript
iains published this revision for review.Jan 3 2023, 2:58 PM
iains added reviewers: ChuanqiXu, dblaikie.
iains added a subscriber: Restricted Project.
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2023, 2:59 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

[module.import]p1 says:

In a module unit, all module-import-declarations and export-declarations exporting module-import-declarations shall appear before all other declarations in the declaration-seq of the translation-unit and of the private-module-fragment (if any).

So the following case is invalid:

//--- b.hpp
void func() {}
import a;

//--- c.cpp
module;
#include "b.hpp"
export module c;

I feel we'd better to address such cases in the test.

iains added a comment.EditedJan 4 2023, 1:10 AM

[module.import]p1 says:

In a module unit, all module-import-declarations and export-declarations exporting module-import-declarations shall appear before all other declarations in the declaration-seq of the translation-unit and of the private-module-fragment (if any).

So the following case is invalid:

//--- b.hpp
void func() {}
import a;

//--- c.cpp
module;
#include "b.hpp"
export module c;

I feel we'd better to address such cases in the test.

I am not sure about this - what you are suggesting above would seem to make modules useless when there is a GMF (since there is almost no point to having a GMF that has no decls).

https://eel.is/c++draft/basic.link#1

Make the declaration-seq of a module unit specifically follow the module keyword.

https://eel.is/c++draft/module#import-1 (which you quoted from above) adds to this the PMF - but I do not see that it includes the GMF (since that is neither the declaration-seq of the module unit nor is it the PMF.

(this + 15.5 named Header Unit import is why the original bug is there .. )

From the discussion in https://github.com/llvm/llvm-project/issues/59688, I feel you are correct. But let's wait for we get a clarification.

ChuanqiXu accepted this revision.Jan 5 2023, 6:08 PM

LGTM. Thanks.

This revision is now accepted and ready to land.Jan 5 2023, 6:08 PM
iains updated this revision to Diff 490099.Jan 18 2023, 3:25 AM

rebased

This revision was landed with ongoing or failed builds.Jan 22 2023, 2:23 AM
This revision was automatically updated to reflect the committed changes.