https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125163
Bug ID: 125163
Summary: When a contract predicate exits via exception the
contract violation shows detection_mode as
predicate_false
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: avr5309 at gmail dot com
Target Milestone: ---
I am new to c++26 contracts myself (apologies in case I am wrong) but I believe
I have found a bug in gcc 16+. As per my understanding of
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2900r14.pdf
(especially page 40, the paragraph starting with 'Even though...') the
following code should have detection mode as 'evaluation_exception' (expected
behavior) instead of 'predicate_false' (current behavior).
```cpp
#include <iostream>
#include <contracts>
#include <utility>
auto handle_contract_violation(std::contracts::contract_violation const& cv) ->
void {
std::cerr << "Detection mode: " << std::to_underlying(cv.mode()) << '\n'; //
Prints 1 (predicate_false) instead of expected 2 (evaluation_exception)
}
auto g(int x) -> bool {
if(x == 0) {
throw std::runtime_error("Throwing!");
}
return true;
}
auto f(int x) -> void pre(g(x)) {
}
auto main() -> int {
f(0);
}
```
My reasoning is that, the pre-condition of function f exits via an exception as
function g throws when x = 0.
Also, as per the document mentioned above and as per
https://cppreference.com/cpp/contract/contract_violation the method of
std::contracts::contract_violation that returns the detection mode is
'detection_mode()' and not 'mode()'. But the method 'detection_mode()' is not
defined.