mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-23 19:03:59 +08:00
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.
This commit is contained in:
parent
dde19c600c
commit
2c08ddd3fd
@ -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" } }
|
||||
|
@ -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} } }
|
||||
|
@ -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} } }
|
||||
|
@ -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} } }
|
||||
|
@ -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} } }
|
||||
|
@ -12,5 +12,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# 9 "[^\n]*legacy-3_b.H"\nimport "[^\n]*legacy-3_a.H" \[\[__translated\]\];\nint move \(int X = 10\);\n} } }
|
||||
// { dg-final { scan-file legacy-3_b.i {\n# 9 "[^\n]*legacy-3_b.H"\nimport "[^\n]*legacy-3_a.H" \[\[__translated\]\];\nint move \(int X = 10\);\n} } }
|
||||
|
||||
|
@ -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} } }
|
||||
|
@ -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} } }
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user