问题标签 [dependent-name]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
71 浏览

c++ - std::basic_string::size_type 在 C++20 模式下导致编译错误

这是一个简单的代码,MSVC 2022 在 C++17 模式下编译,但在 C++20 模式下失败:

C++20模式报错无助说明原因:error C3878: syntax error: unexpected token 'identifier' following 'expression'

有趣的是,它只发生在模板函数中,这个反例在 C++20 模式下编译得很好(以及在 C++17 中):

到目前为止,我可以解决问题的唯一方法是使用 auto 而不是显式数据类型,例如:

但我真的很想了解 C++20 与 C++17 相比发生了什么变化,导致这种语法无效,而不是盲目地应用解决方法补丁。