-
Notifications
You must be signed in to change notification settings - Fork 891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REVIEW] Add explicit conversion for fixed_point to bool. #5859
Conversation
Please update the changelog in order to start CI tests. View the gpuCI docs here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks for the fix! Only small change to Doxygen comment
Co-authored-by: Conor Hoekstra <36027403+codereport@users.noreply.github.com>
Codecov Report
@@ Coverage Diff @@
## branch-0.15 #5859 +/- ##
===============================================
+ Coverage 84.10% 84.43% +0.32%
===============================================
Files 80 80
Lines 13094 13403 +309
===============================================
+ Hits 11013 11317 +304
- Misses 2081 2086 +5
Continue to review full report at Codecov.
|
This PR adds an explicit conversion template specialization from
fixed_point
values tobool
. Below, I explain the problem this is solving in case it's helpful for someone in the future.While developing the AST interpreter (#5494), I implemented a logical "and" operator. I noticed that the expression
fixed_point_value && true
tries to convert fixed_point to a bool with this cast operator but fails to compile (bool
passes theis_integral
trait, and is thus an allowed cast by theis_supported_construction_value
trait).The compilation failure is in
left_shift
(it can't compile this line, which tries to multiply the cast-to typebool
by the scale factor. You might wonder why this is happening -- the conversion is marked explicit. The cause is that logical operators perform explicit conversions [1, 2]. References for this behavior are below.[1] https://en.cppreference.com/w/cpp/language/operator_logical (bold added)
[2] https://en.cppreference.com/w/cpp/language/implicit_conversion (under "Contextual conversions", bold added)