From 2c08ddd3fdd4af794ce66dbabb81ba2e6aee0b7c Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 8 Oct 2024 18:26:40 -0400 Subject: libcpp: avoid extra spaces in module preprocessing Within the compiler, module keywords "import", "module", and "export" that are recognized as part of module directives gain an extra trailing space to distinguish them from other non-keyword uses of those words in the code. But when dumping preprocessed output, printing those spaces creates a gratuitous inconsistency with non-modules preprocessing, as revealed by several of the g++.dg/modules/cpp* tests if modules are enabled by default in C++20 mode. libcpp/ChangeLog: * lex.cc (cpp_output_token): Omit terminal space from name. gcc/testsuite/ChangeLog: * g++.dg/modules/cpp-2_c.C: Expect only one space after import. * g++.dg/modules/cpp-5_c.C * g++.dg/modules/dep-2.C * g++.dg/modules/dir-only-2_b.C * g++.dg/modules/pr99050_b.C * g++.dg/modules/inc-xlate-1_b.H * g++.dg/modules/legacy-3_b.H * g++.dg/modules/legacy-3_c.H: Likewise. --- libcpp/lex.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'libcpp') diff --git a/libcpp/lex.cc b/libcpp/lex.cc index 40c5318..f3feadf 100644 --- a/libcpp/lex.cc +++ b/libcpp/lex.cc @@ -4411,14 +4411,17 @@ cpp_output_token (const cpp_token *token, FILE *fp) { size_t i; const unsigned char * name = NODE_NAME (token->val.node.node); - - for (i = 0; i < NODE_LEN (token->val.node.node); i++) + unsigned len = NODE_LEN (token->val.node.node); + + for (i = 0; i < len; i++) if (name[i] & ~0x7F) { unsigned char buffer[10]; i += utf8_to_ucn (buffer, name + i) - 1; fwrite (buffer, 1, 10, fp); } + else if (name[i] == ' ' && i == len - 1) + /* Omit terminal space in "export ". */; else fputc (NODE_NAME (token->val.node.node)[i], fp); } -- cgit v1.1