https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118830
Bug ID: 118830 Summary: Not removing bounds check from vector::at if used with try/catch (which recovers inside the loop) Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` #include <vector> std::vector<int> vector_init() { std::vector<int> v(10'000); for(int i = 0; i < 10'000; ++i) { #ifndef WO_TRY try { #endif v.at(i) = i; #ifndef WO_TRY } catch(...) {} #endif } return v; } ``` We can optimize this with -DWO_TRY at -O2 but without, there is still bounds check inside the loop even though the bounds check is not reachable.