[clang-tools-extra] [clang-tidy] fix cppcoreguidelines-narrowing-conversions false positives when narrowing integer to signed integer in C++20 (PR #116591)

Carlos Galvez via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 1 11:12:31 PST 2024


carlosgalvezp wrote:

We probably should have proper guidelines for aliases. IMO, there should only be a "base -> coding guideline" kind of alias relationship, not the other way around. Coding guidelines should "cherry-pick" (and possibly configure/harden/make more strict) base checks. So in that sense yes, it would make sense to move the check to bugprone and alias to cppcoreguidelines. But I think that's a separate issue.

> but giving the user choice is a plus

Absolutely, I'm not arguing against that, I'm just saying that the _default_ choice should be what the guidelines say.

I still don't understand what problem we are trying to achieve, however. My impression from the PR (please correct me if I'm wrong) is that we want to ignore integer narrowing conversions in C++20, simply because they are well-defined. 

I believe a lot of people (myself included) will disagree with that - like I wrote above, the problem still remains that data is lost, which is exactly what this check is preventing. If one wants to ignore these warnings, one can disable the check or disable warnings on integer conversions which the existing option. Why is that not sufficient?

https://github.com/llvm/llvm-project/pull/116591


More information about the cfe-commits mailing list