Skip to content
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

useless cast [-Wuseless-cast] warnings with gcc 9.5.0 #973

Closed
jeking3 opened this issue Jan 17, 2023 · 0 comments
Closed

useless cast [-Wuseless-cast] warnings with gcc 9.5.0 #973

jeking3 opened this issue Jan 17, 2023 · 0 comments
Labels
bug This issue is a bug. p3 This is a minor priority issue

Comments

@jeking3
Copy link
Contributor

jeking3 commented Jan 17, 2023

When building with gcc 9.5.0 and the flag -Wuseless-cast, the following warnings are given:

include/aws/common/array_list.inl:122:39: warning: useless cast to type ‘void*’ [-Wuseless-cast]
  122 |         aws_secure_zero((void *)list->data, list->current_size);

aws/common/math.inl:89:47: warning: useless cast to type ‘size_t’ {aka ‘long unsigned int’} [-Wuseless-cast]
   89 |     return (size_t)aws_mul_u64_saturating(a, b);
   
aws/common/math.inl:103:50: warning: useless cast to type ‘uint64_t*’ {aka ‘long unsigned int*’} [-Wuseless-cast]
  103 |     return aws_mul_u64_checked(a, b, (uint64_t *)r);

aws/common/math.inl:116:47: warning: useless cast to type ‘size_t’ {aka ‘long unsigned int’} [-Wuseless-cast]
  116 |     return (size_t)aws_add_u64_saturating(a, b);

aws/common/math.inl:130:50: warning: useless cast to type ‘uint64_t*’ {aka ‘long unsigned int*’} [-Wuseless-cast]
  130 |     return aws_add_u64_checked(a, b, (uint64_t *)r);
  
aws/common/math.inl:140:47: warning: useless cast to type ‘size_t’ {aka ‘long unsigned int’} [-Wuseless-cast]
  140 |     return (size_t)aws_sub_u64_saturating(a, b);
  
aws/common/math.inl:150:50: warning: useless cast to type ‘uint64_t*’ {aka ‘long unsigned int*’} [-Wuseless-cast]
  150 |     return aws_sub_u64_checked(a, b, (uint64_t *)r);
@jmklix jmklix added bug This issue is a bug. p3 This is a minor priority issue needs-review This issue or pull request needs review from a core team member. labels Sep 21, 2023
@jmklix jmklix removed the needs-review This issue or pull request needs review from a core team member. label Aug 12, 2024
graebm added a commit that referenced this issue Aug 13, 2024
**Issue:**
#973

This warning exists in GCC only (not Clang), and for C++ only (not C)

**Description of changes:**
- Add `-Wuseless-cast` warning to the "header checker"
- Remove useless casts in `array_list.inl`
- Ignore `-Wuseless-cast` warning in `math.inl`
    - The tricky part is that SOME platforms (Apple and BSD variants) define `size_t` as `unsigned long` and require casting to `uint64_t` (aka `unsigned long long`). While other platforms define `size_t` as `unsigned long long` and warn about useless casts if you cast it to `uint64_t`. My first commit attempted to only do casts on those platforms, but it was more complex than simply ignoring the warning.
@graebm graebm closed this as completed Aug 13, 2024
graebm added a commit to awslabs/aws-c-event-stream that referenced this issue Aug 16, 2024
**Issue #:**
awslabs/aws-c-common#973

**Research:**
6 years ago, PR #5 made these constants `uint32_t` via a cast.

**Description of changes:**
Avoid `-Wuseless-cast` warnings, don't cast `size_t` to `uint32_t` on 32-bit platforms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

3 participants