Skip to content

[struct_pack] use unsigned long long integer literal to silence gcc warnings #953

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

Merged
merged 1 commit into from
May 14, 2025

Conversation

tchaikov
Copy link
Contributor

when building the tree using GCC-15, we have following warnings:

/home/kefu/dev/yalantinglibs/include/ylt/struct_pack/type_calculate.hpp: In function ‘constexpr decltype(auto) struct_pack::detail::get_size_literal()’:
/home/kefu/dev/yalantinglibs/include/ylt/struct_pack/type_calculate.hpp:64:58: warning: integer overflow in expression of type ‘int’ results in ‘-1321368961’ [-Woverflow]
   64 |          static_cast<char>(size / (127 * 127 * 127 * 127 * 127) + 129)}};
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~

because 127 is an int, if the expression evaluates to an constant with cannot be represented with int, the compiler warns. in order to silence the warnings, let's use the ull prefix.

Why

What is changing

Example

@tchaikov
Copy link
Contributor Author

This PR addresses the same issue as #952, but provides a more comprehensive commit message that explains the rationale behind the change. I've created this separate PR to ensure the change is properly documented with the complete context and justification.

@qicosmos
Copy link
Collaborator

Please format the code.

Copy link

for detail, goto summary download Artifacts base-ylt-cov-report(base commit coverage report) and ylt-cov-report(current pull request coverage report)

@tchaikov tchaikov force-pushed the silence-overflow-warnings branch from 3ac5d14 to 2435541 Compare May 14, 2025 02:50
Copy link

for detail, goto summary download Artifacts base-ylt-cov-report(base commit coverage report) and ylt-cov-report(current pull request coverage report)

…arnings

when building the tree using GCC-15, we have following warnings:

```
/home/kefu/dev/yalantinglibs/include/ylt/struct_pack/type_calculate.hpp: In function ‘constexpr decltype(auto) struct_pack::detail::get_size_literal()’:
/home/kefu/dev/yalantinglibs/include/ylt/struct_pack/type_calculate.hpp:64:58: warning: integer overflow in expression of type ‘int’ results in ‘-1321368961’ [-Woverflow]
   64 |          static_cast<char>(size / (127 * 127 * 127 * 127 * 127) + 129)}};
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
```

because `127` is an `int`, if the expression evaluates to an constant
with cannot be represented with `int`, the compiler warns. in order to
silence the warnings, let's use the `ull` prefix.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
@tchaikov tchaikov force-pushed the silence-overflow-warnings branch from 2435541 to 4c8afeb Compare May 14, 2025 03:59
@tchaikov
Copy link
Contributor Author

changlog

  • ran clang-format against the tree

@poor-circle
Copy link
Collaborator

LGTM

Copy link

for detail, goto summary download Artifacts base-ylt-cov-report(base commit coverage report) and ylt-cov-report(current pull request coverage report)

@qicosmos qicosmos merged commit 638ac84 into alibaba:main May 14, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants