https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125904
Bug ID: 125904
Summary: contracts: assertion not evaluated if only statement
in loop body
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ivan.lazaric.gcc at gmail dot com
Target Milestone: ---
```cpp
int main() {
for (int i = 0; i < 10; ++i) {
contract_assert(false);
}
}
```
Compiler flags: "-std=c++26 -fcontracts"
Expected this to raise a contract violation on execution, but nothing happens
Godbolt: https://godbolt.org/z/hsfbW77Gc
If we just add a meaningless `0;` statement to the loop body, it suddenly works
https://godbolt.org/z/ac86Yjh35