https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116813

            Bug ID: 116813
           Summary: std::vector<bool> index check not optimized out with
                    -O2
           Product: gcc
           Version: 13.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sjames at gcc dot gnu.org
  Target Milestone: ---

At -O2 on trunk, we emit an unnecessary comparison for the bool indexing:
```
#include <vector>

int foo(int index) {
    if (index < 0 || index > 4) {
        return false;
    }

    std::vector<int> p = {0, 1, 2, 3, 4, 5};
    std::vector<bool> q = {true, false, true};

    __builtin_printf("%d\n", q[0] == true);

    return p[index];
}
```

At -O3, we don't. Note that the std::vector<bool> -D_GLIBCXX_ASSERTIONS wiring
is new in trunk. Clang always does it AFAICT?

Reply via email to