diff mbox series

c++: Accept non-ASCII bytes in module names [PR120458]

Message ID tencent_B5D5073AE44018E6A52E50AC6A4B183E880A@qq.com
State New
Headers show
Series c++: Accept non-ASCII bytes in module names [PR120458] | expand

Commit Message

hcwanz Nov. 4, 2026, 3:20 p.m. UTC
module.cc's get_module() rejects module names containing non-ASCII
bytes, so importing such a module fails.  [lex.name] makes
module-name an identifier, and identifiers may contain UTF-8 encoded
characters.

  // 依赖.cc
  export module 依赖;
  export unsigned f(unsigned x) { return x + 3; }

  // mid.cc
  export module mid;
  import 依赖;
  export unsigned g(unsigned x) { return f(x); }

  // use.cc
  import mid;
  int main() { return (int)g(1) - 4; }

  $ g++ -std=c++20 -fmodules-ts -finput-charset=UTF-8 -c 依赖.cc
  $ g++ -std=c++20 -fmodules-ts -finput-charset=UTF-8 -c mid.cc
  $ g++ -std=c++20 -fmodules-ts -finput-charset=UTF-8 -c use.cc
  mid: error: 读取已编译模块失败: Bad import dependency

The bytes 0xE4 etc. fail get_module()'s ISALPHA check and make it return
NULL.  Accept any byte with the high bit set; it cannot be '.' or ':' and
is re-validated by get_identifier_with_length().

Bootstrapped and tested on x86_64-linux-gnu with no regressions.
TO BE RUN: check-c++-all.

抵耗

gcc/cp/ChangeLog

2026-11-04 抵耗  hcwanz@qq.com

	* module.cc (get_module): Accept any byte with the high bit set.

Signed-off-by: 抵耗 hcwanz@qq.com
diff mbox series

Patch

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index c07deff28..3ed3fcd49 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -16714,7 +16714,8 @@  get_module (const char *ptr)
 	  break;
       }
     else if (!(ISALPHA (*probe) || *probe == '_'
-	       || (probe != ptr && ISDIGIT (*probe))))
+	       || (probe != ptr && ISDIGIT (*probe))
+	       || ((unsigned char) *probe) >= 0x80))
       return NULL;
 
   return mod;