Skip to content

Commit 676b48d

Browse files
committed
[C++20] [Modules] Diagnose if import statement lakcs a semicolon
Close #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.
1 parent 5fb5713 commit 676b48d

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

clang/lib/Parse/Parser.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,10 +2654,10 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc,
26542654
SeenError = false;
26552655
break;
26562656
}
2657-
if (SeenError) {
2658-
ExpectAndConsumeSemi(diag::err_module_expected_semi);
2657+
ExpectAndConsumeSemi(diag::err_module_expected_semi);
2658+
2659+
if (SeenError)
26592660
return nullptr;
2660-
}
26612661

26622662
DeclResult Import;
26632663
if (HeaderUnit)
@@ -2666,7 +2666,6 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc,
26662666
else if (!Path.empty())
26672667
Import = Actions.ActOnModuleImport(StartLoc, ExportLoc, ImportLoc, Path,
26682668
IsPartition);
2669-
ExpectAndConsumeSemi(diag::err_module_expected_semi);
26702669
if (Import.isInvalid())
26712670
return nullptr;
26722671

clang/test/CXX/basic/basic.link/p3.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export module m; // #1
1515

1616
// Import errors are fatal, so we test them in isolation.
1717
#if IMPORT_ERROR == 1
18-
import x = {}; // expected-error {{module 'x' not found}}
18+
import x = {}; // expected-error {{expected ';' after module name}}
19+
// expected-error@-1 {{module 'x' not found}}
1920

2021
#elif IMPORT_ERROR == 2
2122
struct X;

clang/test/Modules/pr121066.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %clang_cc1 -std=c++20 -fsyntax-only %s -verify
2+
3+
import mod // expected-error {{expected ';' after module name}}
4+
// expected-error@-1 {{module 'mod' not found}}

0 commit comments

Comments
 (0)