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

Fixed int conversion warning #2313

Merged
merged 2 commits into from
May 25, 2021
Merged

Fixed int conversion warning #2313

merged 2 commits into from
May 25, 2021

Conversation

sven-herrmann
Copy link
Contributor

Compiler warns about conversion from int to size_t, thus added explicit cast.

Compiler warns about conversion from int to size_t, thus added explicit cast.
@vitaut
Copy link
Contributor

vitaut commented May 25, 2021

Which compiler? Please post the full warning with context in a comment.

@sven-herrmann
Copy link
Contributor Author

The compiler in use is c++ / gcc

$ gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

Compiler output was:

deps/fmt/include/fmt/format.h: In member function ‘constexpr void fmt::v7::detail::compute_width(fmt::v7::string_view)::count_code_points::operator()(uint32_t, int) const’:
deps/fmt/include/fmt/format.h:553:13: error: conversion to ‘size_t’ {aka ‘long unsigned int’} from ‘int’ may change the sign of the result [-Werror=sign-conversion]
  553 |           1 +
      |           ~~^
  554 |           (error == 0 && cp >= 0x1100 &&
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  555 |            (cp <= 0x115f ||  // Hangul Jamo init. consonants
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  556 |             cp == 0x2329 ||  // LEFT-POINTING ANGLE BRACKET〈
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  557 |             cp == 0x232a ||  // RIGHT-POINTING ANGLE BRACKET 〉
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  558 |             // CJK ... Yi except Unicode Character “〿”:
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  559 |             (cp >= 0x2e80 && cp <= 0xa4cf && cp != 0x303f) ||
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  560 |             (cp >= 0xac00 && cp <= 0xd7a3) ||    // Hangul Syllables
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  561 |             (cp >= 0xf900 && cp <= 0xfaff) ||    // CJK Compatibility Ideographs
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  562 |             (cp >= 0xfe10 && cp <= 0xfe19) ||    // Vertical Forms
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  563 |             (cp >= 0xfe30 && cp <= 0xfe6f) ||    // CJK Compatibility Forms
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  564 |             (cp >= 0xff00 && cp <= 0xff60) ||    // Fullwidth Forms
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  565 |             (cp >= 0xffe0 && cp <= 0xffe6) ||    // Fullwidth Forms
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  566 |             (cp >= 0x20000 && cp <= 0x2fffd) ||  // CJK
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  567 |             (cp >= 0x30000 && cp <= 0x3fffd) ||
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  568 |             // Miscellaneous Symbols and Pictographs + Emoticons:
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  569 |             (cp >= 0x1f300 && cp <= 0x1f64f) ||
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  570 |             // Supplemental Symbols and Pictographs:
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  571 |             (cp >= 0x1f900 && cp <= 0x1f9ff)));
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors

@@ -550,7 +550,7 @@ FMT_CONSTEXPR inline size_t compute_width(string_view s) {
size_t* count;
FMT_CONSTEXPR void operator()(uint32_t cp, int error) const {
*count +=
1 +
size_t(1 +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use to_unsigned instead of a C-style cast.

@vitaut vitaut merged commit 82607ef into fmtlib:master May 25, 2021
@vitaut
Copy link
Contributor

vitaut commented May 25, 2021

Merged, thanks!

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.

2 participants