[PATCH] D136953: [C++20] Diagnose invalid and reserved module names

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 28 08:02:37 PDT 2022


cor3ntin added inline comments.


================
Comment at: clang/lib/Sema/SemaModule.cpp:257
+    else if (PartName.startswith("std") &&
+             (PartName.size() == 3 || isDigit(PartName.drop_front(3)[0])))
+      Reason = /*reserved*/ 1;
----------------



================
Comment at: clang/lib/Sema/SemaModule.cpp:262
+    // diagnose (because we expect system headers to use reserved identifiers).
+    if (Reason != -1 && !getSourceManager().isInSystemHeader(Part.second)) {
+      Diag(Part.second, diag::err_invalid_module_name) << Part.first << Reason;
----------------
I think `module` in a standard header is still invalid. We could not do the check in a  system header at all


================
Comment at: clang/test/Modules/reserved-names.cpp:37
+# 100 "file.cpp" 1 3 // Enter a system header
+export module std;   // expected-error {{module declaration must occur at the start of the translation unit}}
+# 100 "file.cpp" 2 3 // Leave the system header
----------------
you should add a test for `__test`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136953/new/

https://reviews.llvm.org/D136953



More information about the cfe-commits mailing list