-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
g++ (11) -Wuseless-cast gives lots of warnings #2893
Comments
Can you provide the warnings? |
So it turns out 'lots' is 2. I just saw lots because we include it in lots of places. oops.
|
These are hard to fix, because not all architectures have the same definitions for size_t. |
I double checked. In both cases, there is a cast from std::uint64_t len{};
return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler); I case these types are the same, your reported warning makes sense. However, the types do not necessarily need to be the same. Does anyone has an idea how to silence this warning? |
I guess one could use something like the following #include <type_traits>
template<typename T, typename U, std::enable_if_t<!std::is_same<T, U>::value, int> = 0>
T conditional_static_cast(U value)
{
return static_cast<T>(value);
}
template<typename T, typename U, std::enable_if_t<std::is_same<T, U>::value, int> = 0>
T conditional_static_cast(U value)
{
return value;
}
void func()
{
int a = conditional_static_cast<int>(0);
int b = static_cast<int>(0);
} The first line in func gives no warning the second does. |
I think I've dealt with this before, need to look it up. However, the template solution above does seem elegant. |
tnx! |
|
What is the issue you have?
When I compile the 'single include' file on g++ v11 on my Fedora 34 machine with the '-Wuseless-cast' flags enabled then I get lots of warnings.
Please describe the steps to reproduce the issue.
Can you provide a small but working code example?
What is the expected behavior?
And what is the actual behavior instead?
Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchIf you experience a compilation error: can you compile and run the unit tests?
The text was updated successfully, but these errors were encountered: