[clang-tools-extra] [clang-tidy] fix cppcoreguidelines-narrowing-conversions false positives when narrowing integer to signed integer in C++20 (PR #116591)
Congcong Cai via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 25 04:38:23 PST 2024
================
@@ -393,8 +393,14 @@ void NarrowingConversionsCheck::handleIntegralCast(const ASTContext &Context,
const Expr &Lhs,
const Expr &Rhs) {
if (WarnOnIntegerNarrowingConversion) {
+ // From [conv.integral] since C++20
+ // The result is the unique value of the destination type that is congruent
+ // to the source integer modulo 2^N, where N is the width of the destination
+ // type.
+ if (getLangOpts().CPlusPlus20)
+ return;
----------------
HerrCai0907 wrote:
do you think we should apply similar approach to unsigned integer target type also to make the behaviour similar?
but it can be done separately
https://github.com/llvm/llvm-project/pull/116591
More information about the cfe-commits
mailing list