https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125163
--- Comment #2 from Paul Preney <paul at preney dot ca> ---
I verify that this issue also occurs for me --but it is worse. It occurs with
GCC v16.1.0 (as well as GCC v16.1.1).
If the attached issue.cpp code is compiled:
g++ -std=c++26 -O3 -freflection -Wall -Wextra -o issue.exe issue.cpp
g++ -std=c++26 -O3 -freflection -Wall -Wextra
-fcontract-evaluation-semantic=ignore -o issue-ignore.exe issue.cpp
g++ -std=c++26 -O3 -freflection -Wall -Wextra
-fcontract-evaluation-semantic=observe -o issue-observe.exe issue.cpp
g++ -std=c++26 -O3 -freflection -Wall -Wextra
-fcontract-evaluation-semantic=enforce -o issue-enforce.exe issue.cpp
g++ -std=c++26 -O3 -freflection -Wall -Wextra
-fcontract-evaluation-semantic=quick_enforce -o issue-quick_enforce.exe
issue.cpp
Notice that building the quick_enforce executable results in GCC outputting
warnings based on internal variables, e.g.,
issue.cpp: In function ‘void a_func(int)’:
issue.cpp:52:44: warning: ‘D.111518’ may be used uninitialized
[-Wmaybe-uninitialized]
52 | void a_func(int x) pre(precond_check(x)) { }
| ^
issue.cpp:52:20: note: ‘D.111518’ was declared here
52 | void a_func(int x) pre(precond_check(x)) { }
| ^~~~~~~~~~~~~~~~~~~~~
In function ‘void a_func(int)’,
inlined from ‘int main()’ at issue.cpp:60:11:
issue.cpp:52:44: warning: ‘D.111518’ is used uninitialized [-Wuninitialized]
52 | void a_func(int x) pre(precond_check(x)) { }
| ^
issue.cpp:52:20: note: ‘D.111518’ was declared here
52 | void a_func(int x) pre(precond_check(x)) { }
| ^~~~~~~~~~~~~~~~~~~~~
and these warnings should not be occurring (so that is likely an issue).
When the above issue.cpp executables are run, they produce the following
outputs (for completeness I post such below):
./issue.exe
BEGIN:
main: BEFORE CALL
ISSUE: std::contracts::contract_violation::detection_mode() is not defined
ISSUE: std::contracts::contract_violation::evaluation_exception() is not
defined
ISSUE: incorrect detection mode: predicate_false
terminate called after throwing an instance of 'std::runtime_error'
what(): x is zero
$ ./issue-ignore.exe
BEGIN:
main: BEFORE CALL
main: AFTER CALL
END.
$ ./issue-observe.exe
BEGIN:
main: BEFORE CALL
ISSUE: std::contracts::contract_violation::detection_mode() is not defined
ISSUE: std::contracts::contract_violation::evaluation_exception() is not
defined
ISSUE: incorrect detection mode: predicate_false
EXCEPTION (std::exception): x is zero
END.
$ ./issue-enforce.exe
BEGIN:
main: BEFORE CALL
ISSUE: std::contracts::contract_violation::detection_mode() is not defined
ISSUE: std::contracts::contract_violation::evaluation_exception() is not
defined
ISSUE: incorrect detection mode: predicate_false
terminate called after throwing an instance of 'std::runtime_error'
what(): x is zero
$ ./issue-quick_enforce.exe
BEGIN:
main: BEFORE CALL
terminate called after throwing an instance of 'std::runtime_error'
what(): x is zero
The issues are:
* The value for detection_mode is not always set properly (e.g., per this
bug's original poster's message), e.g., the value appears to be incorrect in
the observe and enforce cases.
* std::contracts::contract_violation::detection_mode() is not defined (i.e.,
the mode() function needs to be renamed)
* std::contracts::contract_violation::evaluation_exception() is not defined.
The relevant pages of P2900R14 are:
* detection_mode(): pages 58, 60, 61, 114, 115
* evaluation_exception(): pages 58, 60, 61, 144, 115