https://gcc.gnu.org/g:7512f0bbbea33c20c9e691d081b1eb5050f6fd22

commit r17-920-g7512f0bbbea33c20c9e691d081b1eb5050f6fd22
Author: Jean-Christian CÎRSTEA <[email protected]>
Date:   Sun Mar 22 19:57:42 2026 +0200

    libcody: allow non-ASCII module names [PR120458]
    
    Before this commit, attempting to use non-ASCII characters in quoted
    words failed, even though the protocol allows the usage of such
    characters in quoted words. To fix this:
    
    1. Remove `c >= 0x7f` comparison when parsing a quoted word.
    2. Use `unsigned char` instead of `char` such that `c < 0x20` fails for
       non-ASCII characters.
    
            PR c++/120458
    
    libcody/ChangeLog:
    
            * buffer.cc (S2C): Allow non-ASCII chars in quoted words.
            * cody.hh: Use unsigned char for S2C().
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/README: Explain purpose of modules/ dir.
            * g++.dg/modules/pr120458-1_a.C: Define non-ASCII module with
            default mapper.
            * g++.dg/modules/pr120458-1_b.C: Import non-ASCII module with
            default mapper.
            * g++.dg/modules/pr120458-2_a.C: Define non-ASCII module with
            a file as mapper.
            * g++.dg/modules/pr120458-2_b.C: Import non-ASCII module with
            a file as mapper.
            * g++.dg/modules/pr120458-2.map: Define mapping for pr120458-2
            test case.
    
    Signed-off-by: Jean-Christian CÎRSTEA <[email protected]>

Diff:
---
 gcc/testsuite/g++.dg/README                 |  1 +
 gcc/testsuite/g++.dg/modules/pr120458-1_a.C |  9 +++++++++
 gcc/testsuite/g++.dg/modules/pr120458-1_b.C | 11 +++++++++++
 gcc/testsuite/g++.dg/modules/pr120458-2.map |  2 ++
 gcc/testsuite/g++.dg/modules/pr120458-2_a.C | 11 +++++++++++
 gcc/testsuite/g++.dg/modules/pr120458-2_b.C | 12 ++++++++++++
 libcody/buffer.cc                           |  6 +++---
 libcody/cody.hh                             |  4 ++--
 8 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/g++.dg/README b/gcc/testsuite/g++.dg/README
index a7b3d5b783b7..3301f17b4dfa 100644
--- a/gcc/testsuite/g++.dg/README
+++ b/gcc/testsuite/g++.dg/README
@@ -15,6 +15,7 @@ inherit        Tests for inheritance -- virtual functions, 
multiple inheritance, etc.
 init    Tests for initialization semantics, constructors/destructors, etc.
 lookup  Tests for lookup semantics, namespaces, using, etc.
 lto     Tests for Link Time Optimization.
+modules  Tests for C++20 modules.
 opt     Tests for fixes of bugs with particular optimizations.
 overload Tests for overload resolution and conversions.
 parse   Tests for parsing.
diff --git a/gcc/testsuite/g++.dg/modules/pr120458-1_a.C 
b/gcc/testsuite/g++.dg/modules/pr120458-1_a.C
new file mode 100644
index 000000000000..89d0bb5d2937
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr120458-1_a.C
@@ -0,0 +1,9 @@
+// { dg-module-do link }
+// { dg-additional-options "-fmodules -finput-charset=UTF-8" }
+
+export module 영혼;
+// { dg-module-cmi }
+
+export unsigned f(unsigned x) {
+       return x + 3;
+}
diff --git a/gcc/testsuite/g++.dg/modules/pr120458-1_b.C 
b/gcc/testsuite/g++.dg/modules/pr120458-1_b.C
new file mode 100644
index 000000000000..4b1023d5f3ec
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr120458-1_b.C
@@ -0,0 +1,11 @@
+// { dg-module-do link }
+// { dg-additional-options "-fmodules -finput-charset=UTF-8" }
+
+#include <iostream>
+
+import 영혼;
+
+int main(void) {
+       std::cout << f(13) << '\n';
+       return 0;
+}
diff --git a/gcc/testsuite/g++.dg/modules/pr120458-2.map 
b/gcc/testsuite/g++.dg/modules/pr120458-2.map
new file mode 100644
index 000000000000..86955e41ea1c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr120458-2.map
@@ -0,0 +1,2 @@
+$root .
+灵魂 pr120458_a.gcm
diff --git a/gcc/testsuite/g++.dg/modules/pr120458-2_a.C 
b/gcc/testsuite/g++.dg/modules/pr120458-2_a.C
new file mode 100644
index 000000000000..940f6e771a05
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr120458-2_a.C
@@ -0,0 +1,11 @@
+// { dg-module-do link }
+// { dg-additional-options "-fmodules -fmodule-mapper=[srcdir]/pr120458-2.map 
" }
+// { dg-additional-options "-finput-charset=UTF-8 " }
+// { dg-additional-files "pr120458-2.map" }
+
+export module 灵魂;
+// { dg-module-cmi }
+
+export unsigned f(unsigned x) {
+       return x + 3;
+}
diff --git a/gcc/testsuite/g++.dg/modules/pr120458-2_b.C 
b/gcc/testsuite/g++.dg/modules/pr120458-2_b.C
new file mode 100644
index 000000000000..dc4f66574fd0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr120458-2_b.C
@@ -0,0 +1,12 @@
+// { dg-module-do link }
+// { dg-additional-options "-fmodules -fmodule-mapper=[srcdir]/pr120458-2.map 
" }
+// { dg-additional-options "-finput-charset=UTF-8" }
+
+import 灵魂;
+
+#include <iostream>
+
+int main(void) {
+       std::cout << f(13) << '\n';
+       return 0;
+}
diff --git a/libcody/buffer.cc b/libcody/buffer.cc
index 85c066fef715..d27882b7d4aa 100644
--- a/libcody/buffer.cc
+++ b/libcody/buffer.cc
@@ -30,7 +30,7 @@
 namespace Cody {
 namespace Detail {
 
-static const char CONTINUE = S2C(u8";");
+static const unsigned char CONTINUE = S2C(u8";");
 
 void MessageBuffer::BeginLine ()
 {
@@ -239,7 +239,7 @@ int MessageBuffer::Lex (std::vector<std::string> &result)
 
   for (std::string *word = nullptr;;)
     {
-      char c = *iter;
+      unsigned char c = *iter;
 
       ++iter;
       if (c == S2C(u8" ") || c == S2C(u8"\t"))
@@ -292,7 +292,7 @@ int MessageBuffer::Lex (std::vector<std::string> &result)
                  return EINVAL;
                }
 
-             if (c < S2C(u8" ") || c >= 0x7f)
+             if (c < S2C(u8" "))
                goto malformed;
 
              ++iter;
diff --git a/libcody/cody.hh b/libcody/cody.hh
index 93bce93aa94d..7c852eb3aa1c 100644
--- a/libcody/cody.hh
+++ b/libcody/cody.hh
@@ -49,14 +49,14 @@ namespace Detail  {
 
 #if __cpp_char8_t >= 201811
 template<unsigned I>
-constexpr char S2C (char8_t const (&s)[I])
+constexpr unsigned char S2C (char8_t const (&s)[I])
 {
   static_assert (I == 2, "only single octet strings may be converted");
   return s[0];
 }
 #else
 template<unsigned I>
-constexpr char S2C (char const (&s)[I])
+constexpr unsigned char S2C (char const (&s)[I])
 {
   static_assert (I == 2, "only single octet strings may be converted");
   return s[0];

Reply via email to