diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp @@ -510,6 +510,8 @@ const BuiltinType *RhsType = getBuiltinType(Rhs); if (RhsType == nullptr || LhsType == nullptr) return; + if (LhsType == RhsType) + return; if (RhsType->getKind() == BuiltinType::Bool && LhsType->isSignedInteger()) return handleBooleanToSignedIntegral(Context, SourceLoc, Lhs, Rhs); if (RhsType->isInteger() && LhsType->getKind() == BuiltinType::Bool) @@ -549,6 +551,8 @@ const Expr &Rhs = *Cast.getSubExpr(); if (Lhs.isInstantiationDependent() || Rhs.isInstantiationDependent()) return; + if (getBuiltinType(Lhs) == getBuiltinType(Rhs)) + return; if (handleConditionalOperator(Context, Lhs, Rhs)) return; SourceLocation SourceLoc = Lhs.getExprLoc(); diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp @@ -54,4 +54,11 @@ f = __builtin_nan("0"); // double NaN is not narrowing. } +double false_positive_const_qualified_cast(bool t) { + double b = 1.0; + constexpr double a = __builtin_huge_val(); + // PR49498 The constness difference of 'a' and 'b' results in an implicit cast. + return t ? b : a; +} + } // namespace floats