Skip to content

Warning Wtype-limits since gcc 10.2 #62

@mjacobse

Description

@mjacobse

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions