如何禁用 CMAKE 中的隐式转换更改符号警告

发布于 2025-01-14 00:24:26 字数 513 浏览 5 评论 0原文

有人知道是否有办法禁用 CMAKE 中 clang 发出的这种警告吗?

std::vector<float> v{1.f, 2.f, 1.f};
int i = 1;
float foo = v[i]; // Here we get the warning, variable i should be a size_t

...

Implicit conversion changes signedness: 'int' to 'std::__1::vector<float>::size_type' (aka 'unsigned long')

Clang 编译器向我发出有关 v[i] 的警告,因为它希望我将其转换为 size_t,如果我在任何地方都进行显式转换,这将非常冗长。

另外,我不想使用 size_t。对我来说,这种类型很容易出错,因为在得到负结果时它会破坏标准减法。 (顺便说一句,我的向量永远不会超过 2^31)

Does anybody know if there is a way to disable this kind of warning given by clang in CMAKE please ?

std::vector<float> v{1.f, 2.f, 1.f};
int i = 1;
float foo = v[i]; // Here we get the warning, variable i should be a size_t

...

Implicit conversion changes signedness: 'int' to 'std::__1::vector<float>::size_type' (aka 'unsigned long')

Clang compiler gives me a warning on v[i] as it wants me to cast it as a size_t which is quite verbose if I do explicit casting everywhere.

Also, I don't want to use size_t. For me this type it is error prone as it breaks the standard substraction when getting negative results. (my vectors will never exceed 2^31 btw)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文