This is an archive of the discontinued LLVM Phabricator instance.

[C++20][Modules] Implement P2615R1 revised export diagnostics.
ClosedPublic

Authored by iains on Jun 14 2023, 12:28 PM.

Details

Summary

It has been reported that the current clang errors for, specifically,
static_assert in export contexts are a serious blocker to adoption of
modules in some cases.

There is also implementation divergence with GCC and MSVC allowing the
constructs mentioned below where clang currently rejects them with an
error.

The category of errors [for declarations in an exported context] is:
(unnamed, static_assert, empty and asm decls). These are now permitted
after P2615R1 which was approved by WG21 as a DR (and thus should be
applied to C++20 as well).

This patch removes these diagnostics and amends the testsuite accordingly.

Diff Detail

Event Timeline

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

thanks to Daniela Engert for reporting this and helping identify the current WG21 status on the topic.

Herald added a project: Restricted Project. · View Herald TranscriptJun 14 2023, 12:31 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ChuanqiXu accepted this revision.Jun 19 2023, 12:31 AM

LGTM with comments.

clang/lib/Sema/SemaModule.cpp
822–825
865–878

nit: we prefer shorter indentation.

872

A namespace decl may not be a enum decl.

This revision is now accepted and ready to land.Jun 19 2023, 12:31 AM
iains added a comment.Jun 21 2023, 1:08 PM

I did not do that yet since this patch only implements the removal of unnamed export diagnostics. There will be a follow-on patch shortly that implements the addition of the export specialisation diagnostics and then we can claim P2615R1.

shafik added a subscriber: shafik.Jun 21 2023, 8:47 PM
shafik added inline comments.
clang/lib/Sema/SemaModule.cpp
835

Can you please add the quoted text for clarity. This is especially helpful if the text changes in the future and we are left trying to read the tea leaves to determine motivation.

iains updated this revision to Diff 533554.Jun 22 2023, 4:20 AM

rebased, addressed review comments.

iains marked 4 inline comments as done.Jun 22 2023, 4:25 AM

not sure why the debian CI is reported clang-format errors; I am not seeing them here.

clang/lib/Sema/SemaModule.cpp
822–825

(actually I just moved this code to place it closer to the use-point).

you change is more efficient, indeed, but it alters the behaviour of the diagnostics such that only the first occurrence is reported (which regresses module.interface/p5.cpp).

It seems to me to be more user-friendly to report all the errors at the same time rather than one by one.

This revision was automatically updated to reflect the committed changes.
iains marked an inline comment as done.