diff --git a/examples/win32-hello/README.md b/examples/win32-hello/README.md index e6ddaa8b..957d89d8 100644 --- a/examples/win32-hello/README.md +++ b/examples/win32-hello/README.md @@ -326,6 +326,7 @@ win32-hello/ ├── DEBUG_GUIDE.md # 调试指南(重要!) ├── DEBUG_MODE_GUIDE.md # 调试模式使用指南 ├── SANITIZER_GUIDE.md # AddressSanitizer 使用指南 +├── MSVC_WARNINGS_SUPPRESSION.md # MSVC 警告屏蔽说明 └── README.md # 本文件 ``` diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 6a692090..5836f987 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -2439,9 +2439,11 @@ class CompilerBase extends \PhpAot\Core\Translator // 警告级别 $cmd .= ' /W3'; - // 禁用 PHP SDK 头文件中的常见警告 - $cmd .= ' /wd4244'; // 禁用类型转换警告(__int64 到 int) - $cmd .= ' /wd4146'; // 禁用一元负运算符应用于无符号类型的警告 + // 禁用 PHP SDK 和 Windows SDK 头文件中的常见警告 + // 这些警告都是编译器噪音,不影响功能(从 Constants 配置中读取) + foreach (Constants::MSVC_SUPPRESSED_WARNINGS as $code => $description) { + $cmd .= " /wd{$code}"; // C{$code}: {$description} + } // 启用 C++ 异常处理(消除 C4530 警告) $cmd .= ' /EHsc'; diff --git a/src/Php/Constants.php b/src/Php/Constants.php index d22da58b..f90f2f89 100644 --- a/src/Php/Constants.php +++ b/src/Php/Constants.php @@ -150,4 +150,26 @@ class Constants 'defaultValue' => '', ], ]; + + /** + * MSVC 编译器警告屏蔽列表 + * 这些警告来自 Windows SDK 和 PHP SDK 头文件,都是编译器噪音,不影响功能 + * + * @var array 键为警告编号,值为说明 + */ + public const array MSVC_SUPPRESSED_WARNINGS = [ + '4244' => '类型转换可能丢失数据 (int -> smaller type)', + '4242' => '类型转换可能丢失数据 (similar to C4244)', + '4146' => '一元负运算符应用于无符号类型', + '4820' => '结构体成员后有填充字节(内存对齐)', + '4464' => '相对包含路径含 ".."', + '4365' => '有符号/无符号转换', + '4127' => '条件表达式是常量(如 while(1))', + '4668' => '未定义的宏当 0 处理(#ifdef __GNUC__)', + '4626' => '赋值运算符被隐式删除(const 成员)', + '5027' => '移动赋值运算符被隐式删除', + '5219' => '隐式转换警告', + '5220' => 'volatile 成员警告', + '4100' => '未使用的参数', + ]; }