martinmoene / span-lite

span lite - A C++20-like span for C++98, C++11 and later in a single-file header-only library
Boost Software License 1.0
499 stars 43 forks source link

Warning Wtype-limits since gcc 10.2 #62

Closed mjacobse closed 4 years ago

mjacobse commented 4 years ago

Enabling -Wextra leads to several warnings inside span-lite since gcc 10.2, for example (https://godbolt.org/z/7GrYsM):

<source>:1084:25: warning: comparison of unsigned expression in '>= 0' is always true [-Wtype-limits]
 1084 |         span_EXPECTS( 0 <= idx && idx < size() );
      | 

In many places, an index of size_type is checked to be not negative, which results in this warning if the size_type is an unsigned type (which is the default). If size_type is configured to be signed, the check 0 <= idx is of course reasonable. Not quite sure what the best approach would be. Write a helper template function is_negative that checks the type for signedness first and only then performs the check maybe? Or disable the warning entirely, but maybe it could be useful for other cases?

martinmoene commented 4 years ago

Thanks @mjacobse , will have a look at it when back at a real keyboard next week.

mjacobse commented 4 years ago

Thanks 👍