gul-cpp / gul14

General Utility Library for C++14
https://gul14.info/
GNU Lesser General Public License v2.1
2 stars 1 forks source link

Fix two warnings about implicit casts #33

Closed alt-graph closed 1 year ago

alt-graph commented 1 year ago

This PR fixes two warnings in bit_manip.h that appear when compiling with -Wconversion.

Finii commented 1 year ago

Hmm, did anyone see these warnings?

In file included from ../include/gul14/string_util.h:30:
../include/gul14/string_view.h:328:47: warning: operand of ? changes signedness: 'typename iterator_traits<const char *>::difference_type' (aka 'long') to 'unsigned long' [-Wsign-conversion]
        return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
        ~~~~~~                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/trim.cc:36:27: note: in instantiation of member function 'gul14::basic_string_view<char>::find_first_not_of' requested here
    const auto lpos = str.find_first_not_of(ws_chars);
                          ^
In file included from ../src/trim.cc:24:
In file included from ../include/gul14/trim.h:28:
In file included from ../include/gul14/string_util.h:30:
../include/gul14/string_view.h:344:72: warning: implicit conversion changes signedness: 'gul14::basic_string_view::size_type' (aka 'unsigned long') to 'std::reverse_iterator<const char *>::difference_type' (aka 'long') [-Wsign-conversion]
        const_reverse_iterator iter = find_not_of ( this->crbegin () + pos, this->crend (), s );
                                                                     ~ ^~~
../src/trim.cc:41:27: note: in instantiation of member function 'gul14::basic_string_view<char>::find_last_not_of' requested here
    const auto rpos = str.find_last_not_of(ws_chars);
                          ^
In file included from ../src/trim.cc:24:
In file included from ../include/gul14/trim.h:28:
In file included from ../include/gul14/string_util.h:30:
../include/gul14/string_view.h:358:27: warning: implicit conversion changes signedness: 'typename iterator_traits<reverse_iterator<const char *>>::difference_type' (aka 'long') to 'unsigned long' [-Wsign-conversion]
        return len_ - 1 - std::distance ( first, last );
                        ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/gul14/string_view.h:345:48: note: in instantiation of function template specialization 'gul14::basic_string_view<char>::reverse_distance<std::reverse_iterator<const char *>>' requested here
        return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter );
                                               ^
3 warnings generated.
Finii commented 1 year ago

https://github.com/gul-cpp/gul14/actions/runs/4230859256/jobs/7348684691 Expand Build and run ASAN tests

Maybe we should -Werror?

alt-graph commented 1 year ago

Hmm, did anyone see these warnings?

... in any case there are more warnings, I just fixed them in a single source file.

alt-graph commented 1 year ago

Maybe we should -Werror?

I am not sure. This might also break the CI if Github decides to upgrade their compilers or whatever. Sure, it might uncover some interesting warnings, but is that worth it?

soerengrunewald commented 1 year ago

Maybe we should -Werror?

I am not sure. This might also break the CI if Github decides to upgrade their compilers or whatever. Sure, it might uncover some interesting warnings, but is that worth it?

If it breaks, we can fix it.