Fix narrowing conversions seen by test-gen#3900
Fix narrowing conversions seen by test-gen#3900LAJW merged 2 commits intodiffblue:developfrom LAJW:lajw/narrow
Conversation
src/util/narrow.h
Outdated
| @@ -0,0 +1,34 @@ | |||
| // Copyright 2019 Diffblue Limited. All Rights Reserved. | |||
There was a problem hiding this comment.
You need to use the normal cbmc copyright header here instead. In particular this shouldn't be all rights reserved
| /// Alias for static_cast intended to be used for numeric casting | ||
| /// Rationale: Easier to grep than static_cast | ||
| template <typename output_type, typename input_type> | ||
| output_type narrow_cast(input_type value) |
There was a problem hiding this comment.
If this is derived from Microsoft GSL this might need an appropriate copyright notice to that effect
There was a problem hiding this comment.
Not necessary, I wrote it from scratch in test-gen.
src/util/narrow.h
Outdated
| static_assert( | ||
| std::is_arithmetic<input_type>::value && | ||
| std::is_arithmetic<output_type>::value, | ||
| "numeric_cast is intended only for numeric conversions"); |
There was a problem hiding this comment.
s/numeric_cast/narrow_cast?
src/util/narrow.h
Outdated
| @@ -0,0 +1,34 @@ | |||
| // Copyright 2019 Diffblue Limited. All Rights Reserved. | |||
There was a problem hiding this comment.
Please sync within Diffblue whether that's a copyright mark to use.
src/util/narrow.h
Outdated
| static_assert( | ||
| std::is_arithmetic<input_type>::value && | ||
| std::is_arithmetic<output_type>::value, | ||
| "numeric_cast is intended only for numeric conversions"); |
There was a problem hiding this comment.
The function is called narrow_cast, but it does make we wonder whether we really need both narrow_cast and numeric_cast(_v)?
There was a problem hiding this comment.
Wasn't numeric cast for expr -> mp_integer?
There was a problem hiding this comment.
narrow_cast is intended only to suppress compiler warnings. It isn't meant to handle errors. It works exactly like static_cast. But it's easier to grep.
allredj
left a comment
There was a problem hiding this comment.
🚫
This PR failed Diffblue compatibility checks (cbmc commit: b158de9).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/98356611
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.
Common spurious failures:
- the cbmc commit has disappeared in the mean time (e.g. in a force-push)
- the author is not in the list of contributors (e.g. first-time contributors).
The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.
allredj
left a comment
There was a problem hiding this comment.
🚫
This PR failed Diffblue compatibility checks (cbmc commit: b648a98).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/98450723
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.
Common spurious failures:
- the cbmc commit has disappeared in the mean time (e.g. in a force-push)
- the author is not in the list of contributors (e.g. first-time contributors).
The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.
I want to enable conversion warnings in test-gen. Unfortunately, I can't because CBMC uses unchecked conversions in its headers. Because there were only so few, rather than guard CBMC headers, I decided to just fix them.
I'm also including a
narrow_castandnarrow(inspired by Guidelines Support Library) with this to mark conversion warnings as such.Rationale:
Why
narrowandnarrow_castand why would you careWhy
numeric_castinstead ofstatic_castif they have the same behaviourEach commit message has a non-empty body, explaining why the change was made.
Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
My PR is restricted to a single feature or bugfix.
White-space or formatting changes outside the feature-related changed lines are in commits of their own.