This is an archive of the discontinued LLVM Phabricator instance.

[C++20][Modules] Complete implementation of module.import p7.
ClosedPublic

Authored by iains on Jun 12 2023, 12:47 PM.

Details

Summary

The following test fails to compile TU b.cpp because we are not making the transitively imported modules visible (per [module.import]/p7)

a.cppm:
export module a;

export int foo() {
   return 42;
}

b.cppm:
export module b;
import a;

export int bar();

b.cpp:
module b;

int bar() {
   return foo();
}

clang++ -c -std=c++2b -fmodule-output a.cppm
clang++ -c -std=c++2b -fmodule-output -fprebuilt-module-path=. b.cppm
clang++ -c -std=c++2b -fprebuilt-module-path=. b.cpp
b.cpp:4:12: error: declaration of 'foo' must be imported from module 'a' before it is required
   return foo();

This is fixed by the following patch (which also addresses a FIXME in basic.def.odr/p6.cppm).

Diff Detail

Event Timeline

iains created this revision.Jun 12 2023, 12:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2023, 12:47 PM
Herald added a subscriber: ChuanqiXu. · View Herald Transcript
iains published this revision for review.Jun 12 2023, 12:49 PM
iains edited the summary of this revision. (Show Details)
iains added a reviewer: ChuanqiXu.
iains added a subscriber: Restricted Project.

many thanks to Daniela Engert from bringing this to my attention (and providing a reproducer test case).

Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2023, 12:51 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ChuanqiXu accepted this revision.Jun 12 2023, 6:49 PM

LGTM. Thanks.

This revision is now accepted and ready to land.Jun 12 2023, 6:49 PM
iains updated this revision to Diff 533656.Jun 22 2023, 9:33 AM

rebased and fixed some formatting.