Sor*_*rXD 8 c++ compilation visual-studio
vs2019 版本 16.11.1
\n优化开启时函数参数传递错误
\n下面是我为重现该问题而构建的最小示例代码:
\n#include <iostream>\n\nusing namespace std;\n\nclass foo {\npublic:\n foo() {\n x = 32.0f;\n min_x = 4.0f;\n }\n\n void func(float val) {\n if (val < get_min_value()) {\n val = get_min_value();\n }\n\n inner_func(val);\n }\n\nprotected:\n void inner_func(float val) {\n float old = x;\n x = val;\n inner_print((int)old);\n }\n\n virtual float get_min_value() {\n return min_x;\n }\n\n void inner_print(int val) {\n cout << val << endl;\n }\n\nprivate:\n float x;\n float min_x;\n};\n\nint main() {\n foo f;\n f.func(10.0f);\n\n return 0;\n}\nRun Code Online (Sandbox Code Playgroud)\n正如 @engf-010 所建议的,我已使用 @Bill Lynch 的 Redused-down 版本向 Microsoft 报告了这一点(使用 VS 右上角的反馈按钮):\n C++ 编译器错误:优化时生成的输出不正确打开(适用于 vs2017、vs2019、vs2022)
\nVS 开发者社区中也有类似问题的报告:\n C++ 编译器:打开优化时函数参数传递错误
\n| 归档时间: |
|
| 查看次数: |
351 次 |
| 最近记录: |