File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -513,7 +513,9 @@ void NarrowingConversionsCheck::handleFloatingCast(const ASTContext &Context,
513
513
return ;
514
514
}
515
515
const BuiltinType *FromType = getBuiltinType (Rhs);
516
- if (ToType->getKind () < FromType->getKind ())
516
+ if (!llvm::APFloatBase::isRepresentableBy (
517
+ Context.getFloatTypeSemantics (FromType->desugar ()),
518
+ Context.getFloatTypeSemantics (ToType->desugar ())))
517
519
diagNarrowType (SourceLoc, Lhs, Rhs);
518
520
}
519
521
}
Original file line number Diff line number Diff line change @@ -210,6 +210,11 @@ Changes in existing checks
210
210
<clang-tidy/checks/bugprone/forwarding-reference-overload>` check by fixing
211
211
a crash when determining if an ``enable_if[_t] `` was found.
212
212
213
+ - Improve :doc: `bugprone-narrowing-conversions
214
+ <clang-tidy/checks/bugprone/narrowing-conversions>` to avoid incorrect check
215
+ results when floating point type is not ``float ``, ``double `` and
216
+ ``long double ``.
217
+
213
218
- Improved :doc: `bugprone-optional-value-conversion
214
219
<clang-tidy/checks/bugprone/optional-value-conversion>` to support detecting
215
220
conversion directly by ``std::make_unique `` and ``std::make_shared ``.
Original file line number Diff line number Diff line change @@ -36,6 +36,15 @@ void narrow_double_to_float_not_ok(double d) {
36
36
f = narrow_double_to_float_return ();
37
37
}
38
38
39
+ float narrow_float16_to_float_return (_Float16 f) {
40
+ return f;
41
+ }
42
+
43
+ _Float16 narrow_float_to_float16_return (float f) {
44
+ return f;
45
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: narrowing conversion from 'float' to '_Float16' [bugprone-narrowing-conversions]
46
+ }
47
+
39
48
void narrow_fp_constants () {
40
49
float f;
41
50
f = 0.5 ; // [dcl.init.list] 7.2 : in-range fp constant to narrower float is not a narrowing.
You can’t perform that action at this time.
0 commit comments