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

Warnings from -Wsign-conversion on Gcc 11.4.0 with C++ 20 #124

Open
benblan opened this issue May 19, 2024 · 3 comments
Open

Warnings from -Wsign-conversion on Gcc 11.4.0 with C++ 20 #124

benblan opened this issue May 19, 2024 · 3 comments

Comments

@benblan
Copy link

benblan commented May 19, 2024

Hello,

when I include the library (v4.0.5) in my code, I get the 2 following warnings. Not sure it comes from my code. Maybe the way I include it?

/home/project/extern/utfcpp/utf8/core.h: In instantiation of ‘utf8::internal::utf_error utf8::internal::get_sequence_4(octet_iterator&, octet_iterator, utf8::utfchar32_t&) [with octet_iterator = const char*; utf8::utfchar32_t = char32_t]’:
/home/project/extern/utfcpp/utf8/core.h:277:53:   required from ‘utf8::internal::utf_error utf8::internal::validate_next(octet_iterator&, octet_iterator, utf8::utfchar32_t&) [with octet_iterator = const char*; utf8::utfchar32_t = char32_t]’
/home/project/extern/utfcpp/utf8/core.h:305:45:   required from ‘utf8::internal::utf_error utf8::internal::validate_next(octet_iterator&, octet_iterator) [with octet_iterator = const char*]’
/home/project/extern/utfcpp/utf8/core.h:437:79:   required from ‘octet_iterator utf8::find_invalid(octet_iterator, octet_iterator) [with octet_iterator = const char*]’
/home/project/extern/utfcpp/utf8/core.h:447:28:   required from here
/home/project/extern/utfcpp/utf8/core.h:237:20: warning: conversion to ‘unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion]
  237 |         code_point += (utf8::internal::mask8(*it) << 6) & 0xfff;
      |         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/project/extern/utfcpp/utf8/core.h: In instantiation of ‘utf8::internal::utf_error utf8::internal::get_sequence_3(octet_iterator&, octet_iterator, utf8::utfchar32_t&) [with octet_iterator = __gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >; utf8::utfchar32_t = char32_t]’:
/home/project/extern/utfcpp/utf8/core.h:274:53:   required from ‘utf8::internal::utf_error utf8::internal::validate_next(octet_iterator&, octet_iterator, utf8::utfchar32_t&) [with octet_iterator = __gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >; utf8::utfchar32_t = char32_t]’
/home/project/extern/utfcpp/utf8/core.h:305:45:   required from ‘utf8::internal::utf_error utf8::internal::validate_next(octet_iterator&, octet_iterator) [with octet_iterator = __gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >]’
/home/project/extern/utfcpp/utf8/core.h:437:79:   required from ‘octet_iterator utf8::find_invalid(octet_iterator, octet_iterator) [with octet_iterator = __gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >]’
/home/project/extern/utfcpp/utf8/core.h:452:59:   required from here
/home/project/extern/utfcpp/utf8/core.h:218:20: warning: conversion to ‘unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion]
  218 |         code_point += (*it) & 0x3f;
      |         ~~~~~~~~~~~^~~~~~~~~~~~~~~
@nemtrif
Copy link
Owner

nemtrif commented May 21, 2024

Would you post a code snippet that causes the warnings?

@benblan
Copy link
Author

benblan commented May 22, 2024

Well, I just have to include the file, I don't have to call some code:
#include "utf8.h"

@benblan
Copy link
Author

benblan commented Jun 1, 2024

Hello,
The second warning:

/home/project/extern/utfcpp/utf8/core.h: In instantiation of ‘utf8::internal::utf_error utf8::internal::get_sequence_3(octet_iterator&, octet_iterator, utf8::utfchar32_t&) [with octet_iterator = __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >; utf8::utfchar32_t = char32_t]’:
/home/project/extern/utfcpp/utf8/core.h:274:53:   required from ‘utf8::internal::utf_error utf8::internal::validate_next(octet_iterator&, octet_iterator, utf8::utfchar32_t&) [with octet_iterator = __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >; utf8::utfchar32_t = char32_t]’
/home/project/extern/utfcpp/utf8/checked.h:154:69:   required from ‘utf8::utfchar32_t utf8::next(octet_iterator&, octet_iterator) [with octet_iterator = __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >; utf8::utfchar32_t = char32_t]’
/home/project/engine/src/gfx/font.cpp:158:40:   required from here

is caused by this code for example:

void Font::drawText(int x, int y, const std::string& text, bool x2) {
    int sc = x2 ? 2 : 1;
    int ox = x;

    std::string newText(text);
    std::string::iterator b = newText.begin();
    std::string::iterator e = newText.end();
    while ( b != e ) {
        try {
            auto codePoint = utf8::next(b,e);
            //...
        } catch (const utf8::invalid_utf8& exc) {
            continue;
        }
    } //end of while
}

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

No branches or pull requests

2 participants