Tested x86_64-pc-linux-gnu, will apply to trunk with the rest of this patch series.
-- 8< -- 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. --- gcc/testsuite/g++.dg/modules/cpp-2_c.C | 2 +- gcc/testsuite/g++.dg/modules/cpp-5_c.C | 2 +- gcc/testsuite/g++.dg/modules/dep-2.C | 2 +- gcc/testsuite/g++.dg/modules/dir-only-2_b.C | 10 +++++----- gcc/testsuite/g++.dg/modules/pr99050_b.C | 2 +- libcpp/lex.cc | 7 +++++-- gcc/testsuite/g++.dg/modules/inc-xlate-1_b.H | 2 +- gcc/testsuite/g++.dg/modules/legacy-3_b.H | 2 +- gcc/testsuite/g++.dg/modules/legacy-3_c.H | 2 +- 9 files changed, 17 insertions(+), 14 deletions(-) diff --git a/gcc/testsuite/g++.dg/modules/cpp-2_c.C b/gcc/testsuite/g++.dg/modules/cpp-2_c.C index c6e02b7800a..2a79031eb34 100644 --- a/gcc/testsuite/g++.dg/modules/cpp-2_c.C +++ b/gcc/testsuite/g++.dg/modules/cpp-2_c.C @@ -11,7 +11,7 @@ import nope; #endif think -// { dg-final { scan-file cpp-2_c.i {cpp-2_c.C"\n\n\n\nmodule bob;\n#pragma GCC unused\nimport "[^\n]*\./cpp-2_b.H" \[\[ CLOSE ]];\nimport "[^\n]*cpp-2_a.H" \[\[ ]];\n} } } +// { dg-final { scan-file cpp-2_c.i {cpp-2_c.C"\n\n\n\nmodule bob;\n#pragma GCC unused\nimport "[^\n]*\./cpp-2_b.H" \[\[ CLOSE ]];\nimport "[^\n]*cpp-2_a.H" \[\[ ]];\n} } } // { dg-final { scan-file cpp-2_c.i "int i;" } } // { dg-final { scan-file-not cpp-2_c.i "import *nope;" } } // { dg-final { scan-file cpp-2_c.i "THIS IS STDIO\n" } } diff --git a/gcc/testsuite/g++.dg/modules/cpp-5_c.C b/gcc/testsuite/g++.dg/modules/cpp-5_c.C index e0a78a516ae..7f75a228cda 100644 --- a/gcc/testsuite/g++.dg/modules/cpp-5_c.C +++ b/gcc/testsuite/g++.dg/modules/cpp-5_c.C @@ -7,4 +7,4 @@ import "cpp-5_a.H"; Q -// { dg-final { scan-file cpp-5_c.i {\nimport "[^\n]*cpp-5_a.H";\n\n0\n} } } +// { dg-final { scan-file cpp-5_c.i {\nimport "[^\n]*cpp-5_a.H";\n\n0\n} } } diff --git a/gcc/testsuite/g++.dg/modules/dep-2.C b/gcc/testsuite/g++.dg/modules/dep-2.C index 2dccab3554d..3c869755785 100644 --- a/gcc/testsuite/g++.dg/modules/dep-2.C +++ b/gcc/testsuite/g++.dg/modules/dep-2.C @@ -9,4 +9,4 @@ module m:part; // { dg-final { scan-file dep-2.d {\ngcm.cache/m:part\.gcm:| dep-2\.o} } } // { dg-final { scan-file dep-2.d {\n\.PHONY: m:part\.c\+\+-module} } } -// { dg-final { scan-file dep-2.i {\nmodule m:part;\n} } } +// { dg-final { scan-file dep-2.i {\nmodule m:part;\n} } } diff --git a/gcc/testsuite/g++.dg/modules/dir-only-2_b.C b/gcc/testsuite/g++.dg/modules/dir-only-2_b.C index 1009ae5b3a2..b1ef9b95e58 100644 --- a/gcc/testsuite/g++.dg/modules/dir-only-2_b.C +++ b/gcc/testsuite/g++.dg/modules/dir-only-2_b.C @@ -21,8 +21,8 @@ export module bob; export import q; -// { dg-final { scan-file dir-only-2_b.i {// a comment\nmodule ;\nfrob} } } -// { dg-final { scan-file dir-only-2_b.i {frob\nexport\nimport foo;\nimport 7;} } } -// { dg-final { scan-file dir-only-2_b.i {import "[^\n]*/dir-only-2_a.H";\nimport "[^\n]*/dir-only-2_a.H";\nX} } } -// { dg-final { scan-file dir-only-2_b.i {export module bob;\n\nexport import q;} } } -// { dg-final { scan-file dir-only-2_b.i {import sing;\n\n\n// comment} } } +// { dg-final { scan-file dir-only-2_b.i {// a comment\nmodule;\nfrob} } } +// { dg-final { scan-file dir-only-2_b.i {frob\nexport\nimport foo;\nimport 7;} } } +// { dg-final { scan-file dir-only-2_b.i {import "[^\n]*/dir-only-2_a.H";\nimport "[^\n]*/dir-only-2_a.H";\nX} } } +// { dg-final { scan-file dir-only-2_b.i {export module bob;\n\nexport import q;} } } +// { dg-final { scan-file dir-only-2_b.i {import sing;\n\n\n// comment} } } diff --git a/gcc/testsuite/g++.dg/modules/pr99050_b.C b/gcc/testsuite/g++.dg/modules/pr99050_b.C index 439e216eb16..f2c95631321 100644 --- a/gcc/testsuite/g++.dg/modules/pr99050_b.C +++ b/gcc/testsuite/g++.dg/modules/pr99050_b.C @@ -4,4 +4,4 @@ int main () {} -// { dg-final { scan-file pr99050_b.i {import "[^\n]*99050_a.H" \[\[__translated\]\];\n} } } +// { dg-final { scan-file pr99050_b.i {import "[^\n]*99050_a.H" \[\[__translated\]\];\n} } } diff --git a/libcpp/lex.cc b/libcpp/lex.cc index 4025e5cd3d9..57c339a753a 100644 --- a/libcpp/lex.cc +++ b/libcpp/lex.cc @@ -4444,14 +4444,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); } diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-1_b.H b/gcc/testsuite/g++.dg/modules/inc-xlate-1_b.H index 50b27efa7ef..872ebf3de98 100644 --- a/gcc/testsuite/g++.dg/modules/inc-xlate-1_b.H +++ b/gcc/testsuite/g++.dg/modules/inc-xlate-1_b.H @@ -18,4 +18,4 @@ extern "C" { #endif #endif -// { dg-final { scan-file inc-xlate-1_b.i {import "[^\n]*inc-xlate-1_a.H" \[\[__translated\]\];\n} } } +// { dg-final { scan-file inc-xlate-1_b.i {import "[^\n]*inc-xlate-1_a.H" \[\[__translated\]\];\n} } } diff --git a/gcc/testsuite/g++.dg/modules/legacy-3_b.H b/gcc/testsuite/g++.dg/modules/legacy-3_b.H index 145bfbbddd1..52eecd72c68 100644 --- a/gcc/testsuite/g++.dg/modules/legacy-3_b.H +++ b/gcc/testsuite/g++.dg/modules/legacy-3_b.H @@ -16,5 +16,5 @@ int move (int X = __LINE__); // Capture __LINE__ in a non-definition // this should not be diverted #include "legacy-3.h" -// { dg-final { scan-file legacy-3_b.i {\n# 13 "[^\n]*legacy-3_b.H"\nimport "[^\n]*legacy-3_a.H" \[\[__translated\]\];\nint move \(int X = 14\);\n} } } +// { dg-final { scan-file legacy-3_b.i {\n# 13 "[^\n]*legacy-3_b.H"\nimport "[^\n]*legacy-3_a.H" \[\[__translated\]\];\nint move \(int X = 14\);\n} } } diff --git a/gcc/testsuite/g++.dg/modules/legacy-3_c.H b/gcc/testsuite/g++.dg/modules/legacy-3_c.H index 56b81722997..63c9bcf7078 100644 --- a/gcc/testsuite/g++.dg/modules/legacy-3_c.H +++ b/gcc/testsuite/g++.dg/modules/legacy-3_c.H @@ -17,7 +17,7 @@ MARK3 __LINE__ // this should not be translated #include "legacy-3.h" -// { dg-final { scan-file legacy-3_c.i {MARK1 8\nimport "[^\n]*legacy-3_a.H" \[\[__translated\]\];\nMARK2 10\n} } } +// { dg-final { scan-file legacy-3_c.i {MARK1 8\nimport "[^\n]*legacy-3_a.H" \[\[__translated\]\];\nMARK2 10\n} } } // We should have stopped. // { dg-final { scan-file legacy-3_c.i {move} } } // { dg-final { scan-file legacy-3_c.i {MARK2 13\n\nMARK3 15\n} } } -- 2.46.2