Skip to content

Vector[ ] range check: Tautological compare #9

Description

@TamaMcGlinn

If I include std_lib_facilities.h, I get:

$ clang++ FirstStepsInCPP.cpp -std=c++14
In file included from FirstStepsInCPP.cpp:4:
./book_headers/std_lib_facilities.h:107:8: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
                if (i<0||size()<=i) throw Range_error(i);
                    ~^~
./book_headers/std_lib_facilities.h:113:8: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
                if (i<0||size()<=i) throw Range_error(i);
                    ~^~
2 warnings generated.

Which is absolutely true; i is an unsigned int so why bother checking for negative values?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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