[clang] 676b48d - [C++20] [Modules] Diagnose if import statement lakcs a semicolon
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 25 01:48:47 PST 2024
Author: Chuanqi Xu
Date: 2024-12-25T17:45:28+08:00
New Revision: 676b48d1ccd8223bb0bd889cce13e6faecd20c6d
URL: https://github.com/llvm/llvm-project/commit/676b48d1ccd8223bb0bd889cce13e6faecd20c6d
DIFF: https://github.com/llvm/llvm-project/commit/676b48d1ccd8223bb0bd889cce13e6faecd20c6d.diff
LOG: [C++20] [Modules] Diagnose if import statement lakcs a semicolon
Close https://github.com/llvm/llvm-project/issues/121066
Now we will diagnose that the import statement lacks a semicolon as
expected. Note that the original "not found" diagnose message remains.
I meant to remove that, but the test shows it might be more complex
process (other unexpected diagnose shows up). Given the importance of
the issue, I chose to not dig deeper.
Added:
clang/test/Modules/pr121066.cpp
Modified:
clang/lib/Parse/Parser.cpp
clang/test/CXX/basic/basic.link/p3.cpp
Removed:
################################################################################
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 8ba6a5dce8a994..0710542f5e938e 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -2654,10 +2654,10 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc,
SeenError = false;
break;
}
- if (SeenError) {
- ExpectAndConsumeSemi(diag::err_module_expected_semi);
+ ExpectAndConsumeSemi(diag::err_module_expected_semi);
+
+ if (SeenError)
return nullptr;
- }
DeclResult Import;
if (HeaderUnit)
@@ -2666,7 +2666,6 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc,
else if (!Path.empty())
Import = Actions.ActOnModuleImport(StartLoc, ExportLoc, ImportLoc, Path,
IsPartition);
- ExpectAndConsumeSemi(diag::err_module_expected_semi);
if (Import.isInvalid())
return nullptr;
diff --git a/clang/test/CXX/basic/basic.link/p3.cpp b/clang/test/CXX/basic/basic.link/p3.cpp
index 23f39d11b655a6..01202264d2591b 100644
--- a/clang/test/CXX/basic/basic.link/p3.cpp
+++ b/clang/test/CXX/basic/basic.link/p3.cpp
@@ -15,7 +15,8 @@ export module m; // #1
// Import errors are fatal, so we test them in isolation.
#if IMPORT_ERROR == 1
-import x = {}; // expected-error {{module 'x' not found}}
+import x = {}; // expected-error {{expected ';' after module name}}
+ // expected-error at -1 {{module 'x' not found}}
#elif IMPORT_ERROR == 2
struct X;
diff --git a/clang/test/Modules/pr121066.cpp b/clang/test/Modules/pr121066.cpp
new file mode 100644
index 00000000000000..e92a81c53d683f
--- /dev/null
+++ b/clang/test/Modules/pr121066.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only %s -verify
+
+import mod // expected-error {{expected ';' after module name}}
+ // expected-error at -1 {{module 'mod' not found}}
More information about the cfe-commits
mailing list