Skip to content

Commit 82612f8

Browse files
committed
Refine err_invalid_module_or_import_directive and comments in Lexer.cpp
Signed-off-by: yronglin <[email protected]>
1 parent 3becb46 commit 82612f8

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,11 +1780,11 @@ def ext_bit_int : Extension<
17801780
let CategoryName = "Modules Issue" in {
17811781
def err_invalid_module_or_import_directive : Error<
17821782
"the %select{module|import}0 directive is ill-formed, "
1783-
"%select{module contextual keyword must be immediately "
1783+
"%select{module keyword must be immediately "
17841784
"followed on the same line by an identifier, "
17851785
"or a ';' after being at the start of a line, or preceded by "
17861786
"an export keyword at the start of a line|"
1787-
"import contextual keyword must be immediately followed "
1787+
"import keyword must be immediately followed "
17881788
"on the same line by an identifier, '<', '\"', or ':', but not '::', "
17891789
"after being at the start of a line or preceded by an export at "
17901790
"the start of the line}0">;

clang/lib/Lex/Lexer.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4041,13 +4041,9 @@ bool Lexer::LexTokenInternal(Token &Result, bool TokAtPhysicalStartOfLine) {
40414041
MIOpt.ReadToken();
40424042
bool returnedToken = LexIdentifierContinue(Result, CurPtr);
40434043

4044-
// Check eof token first, because eof token may be encountered in
4045-
// LexIdentifierContinue, and the current lexer will be deleted in
4046-
// HandleEndOfFile, causing members(eg. LangOpts) to become an inaccessible
4047-
// dangling reference.
4048-
//
4049-
// FIXME: Whether a more reasonable memory management method needed? such as
4050-
// delaying the deletion of the current Lexer.
4044+
// Check eof token first, because EOF may be encountered in
4045+
// LexIdentifierContinue, and the current lexer may then be made invalid by
4046+
// HandleEndOfFile.
40514047
if (returnedToken && Result.isNot(tok::eof) &&
40524048
Result.isModuleContextualKeyword(LangOpts) && !LexingRawMode &&
40534049
!Is_PragmaLexer && !ParsingPreprocessorDirective && PP &&

clang/test/CXX/module/cpp.pre/p1.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ import rightpad; // preprocessing directive
5454
import :part; // preprocessing directive
5555

5656
//--- module_decl_not_in_same_line.cpp
57-
module // expected-error {{the module directive is ill-formed, module contextual keyword must be immediately followed on the same line by an identifier, or a ';' after being at the start of a line, or preceded by an export keyword at the start of a line}}
58-
;export module M; // expected-error {{the module directive is ill-formed, module contextual keyword must be immediately followed on the same line by an identifier, or a ';' after being at the start of a line, or preceded by an export keyword at the start of a line}}
57+
module // expected-error {{the module directive is ill-formed, module keyword must be immediately followed on the same line by an identifier, or a ';' after being at the start of a line, or preceded by an export keyword at the start of a line}}
58+
;export module M; // expected-error {{the module directive is ill-formed, module keyword must be immediately followed on the same line by an identifier, or a ';' after being at the start of a line, or preceded by an export keyword at the start of a line}}
5959

6060
//--- foo.cppm
6161
export module foo;
6262

6363
//--- import_decl_not_in_same_line.cpp
6464
export module M;
65-
export // expected-error {{the import directive is ill-formed, import contextual keyword must be immediately followed on the same line by an identifier, '<', '"', or ':', but not '::', after being at the start of a line or preceded by an export at the start of the line}}
65+
export // expected-error {{the import directive is ill-formed, import keyword must be immediately followed on the same line by an identifier, '<', '"', or ':', but not '::', after being at the start of a line or preceded by an export at the start of the line}}
6666
import
6767
foo;
6868

69-
export // expected-error {{the import directive is ill-formed, import contextual keyword must be immediately followed on the same line by an identifier, '<', '"', or ':', but not '::', after being at the start of a line or preceded by an export at the start of the line}}
69+
export // expected-error {{the import directive is ill-formed, import keyword must be immediately followed on the same line by an identifier, '<', '"', or ':', but not '::', after being at the start of a line or preceded by an export at the start of the line}}
7070
import foo;
7171

7272
//--- not_import.cpp

0 commit comments

Comments
 (0)