在 Visual Studio 中,如何检测三元运算符 c?e1:e2 在 C++ 代码中出现的所有情况,其中 e1 和 e2 的类型不同?

问题描述

在 Visual Studio 中,如何检测三元运算符 c?e1:e2 在 C++ 代码中出现的所有情况,其中 e1e2 的类型不同?

我对检测 c?1:2 不感兴趣,而例如我对 c?0:std::string{"Hello world"} 感兴趣。

解决方法

如果您的代码使用 Visual Studio 编译,您可以使用:/Zc:ternary

此选项启用标准符合行为,其中类型不能无关。

https://docs.microsoft.com/en-us/cpp/build/reference/zc-ternary?view=msvc-160

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...